code.vegaprotocol.io/vega@v0.79.0/core/integration/features/successor-markets-ELS.feature (about)

     1  Feature: Simple example of successor markets
     2  
     3    Background:
     4      Given time is updated to "2019-11-30T00:00:00Z"
     5      And the liquidity monitoring parameters:
     6        | name               | triggering ratio | time window | scaling factor |
     7        | lqm-params         | 0.01             | 10s         | 10             |  
     8      And the following network parameters are set:
     9        | name                                         | value |
    10        | network.markPriceUpdateMaximumFrequency      | 0s    |
    11        | market.auction.minimumDuration               | 1     |
    12        | market.fee.factors.infrastructureFee         | 0.001 |
    13        | market.fee.factors.makerFee                  | 0.004 |
    14        | market.value.windowLength                    | 60s   |
    15        | market.liquidity.bondPenaltyParameter        | 0.1   |
    16        | validators.epoch.length                      | 5s    |
    17        | market.liquidity.stakeToCcyVolume            | 0.2   |
    18        | market.liquidity.successorLaunchWindowLength | 1h    |
    19      And the following assets are registered:
    20        | id  | decimal places |
    21        | ETH | 0              |
    22        | USD | 0              |
    23      Given the log normal risk model named "lognormal-risk-model-fish":
    24        | risk aversion | tau  | mu | r   | sigma |
    25        | 0.001         | 0.01 | 0  | 0.0 | 1.2   |
    26      And the margin calculator named "margin-calculator-1":
    27        | search factor | initial factor | release factor |
    28        | 1.2           | 1.5            | 2              |
    29  
    30      # Create some oracles
    31      ## oracle for parent
    32      And the oracle spec for settlement data filtering data from "0xCAFECAFE1" named "ethDec19Oracle":
    33        | property         | type         | binding         |
    34        | prices.ETH.value | TYPE_INTEGER | settlement data |
    35      And the oracle spec for trading termination filtering data from "0xCAFECAFE1" named "ethDec19Oracle":
    36        | property           | type         | binding             |
    37        | trading.terminated | TYPE_BOOLEAN | trading termination |
    38      And the settlement data decimals for the oracle named "ethDec19Oracle" is given in "5" decimal places
    39      ## oracle for a successor
    40      And the oracle spec for settlement data filtering data from "0xCAFECAFE" named "ethDec20Oracle":
    41        | property         | type         | binding         |
    42        | prices.ETH.value | TYPE_INTEGER | settlement data |
    43      And the oracle spec for trading termination filtering data from "0xCAFECAFE" named "ethDec20Oracle":
    44        | property           | type         | binding             |
    45        | trading.terminated | TYPE_BOOLEAN | trading termination |
    46      And the settlement data decimals for the oracle named "ethDec20Oracle" is given in "5" decimal places
    47  
    48      And the liquidity sla params named "SLA":
    49        | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    50        | 1.0         | 0.5                          | 1                             | 1.0                    |
    51      And the average block duration is "1"
    52  # All parties have 1,000,000.000,000,000,000,000,000
    53      # Add as many parties as needed here
    54      And the parties deposit on asset's general account the following amount:
    55        | party   | asset | amount      |
    56        | lpprov1 | USD   | 2000000000  |
    57        | lpprov2 | USD   | 20000000000 |
    58        | lpprov3 | USD   | 20000000000 |
    59        | lpprov4 | USD   | 20000000000 |
    60        | trader1 | USD   | 2000000     |
    61        | trader2 | USD   | 2000000     |
    62        | trader3 | USD   | 2000000     |
    63        | trader4 | USD   | 2000000     |
    64        | trader5 | USD   | 22000       |
    65  
    66    @SuccessorMarketActive @NoPerp @Liquidation
    67    Scenario: 001 Enact a successor market when the parent market is still active; Two proposals that name the same parent can be submitted; 0081-SUCM-005, 0081-SUCM-006, 0081-SUCM-020, 0081-SUCM-021, 0081-SUCM-022
    68      Given the markets:
    69        | id        | quote name | asset | liquidity monitoring | risk model                | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | decimal places | position decimal places | parent market id | insurance pool fraction | successor auction | sla params |
    70        | ETH/DEC19 | ETH        | USD   | lqm-params           | lognormal-risk-model-fish | margin-calculator-1       | 1                | default-none | default-none     | ethDec19Oracle         | 0.1                    | 0                         | 0              | 0                       |                  |                         |                   | SLA        |
    71        | ETH/DEC20 | ETH        | USD   | lqm-params           | default-st-risk-model     | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.1                    | 0                         | 0              | 0                       | ETH/DEC19        | 0.6                     | 10                | SLA        |
    72        | ETH/DEC21 | ETH        | USD   | lqm-params           | default-st-risk-model     | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.1                    | 0                         | 0              | 0                       | ETH/DEC19        | 0.6                     | 10                | SLA        |
    73      And the following network parameters are set:
    74        | name                                               | value |
    75        | market.liquidity.providersFeeCalculationTimeStep | 5s    |
    76      And the parties submit the following liquidity provision:
    77        | id  | party   | market id | commitment amount | fee | lp type    |
    78        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
    79        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
    80        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
    81        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
    82      And the parties place the following orders:
    83        | party   | market id | side | volume | price | resulting trades | type       | tif     |
    84        | trader1 | ETH/DEC19 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    85        | trader1 | ETH/DEC19 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
    86        | trader1 | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    87        | trader2 | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    88      When the opening auction period ends for market "ETH/DEC19"
    89      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    90      Then the market data for the market "ETH/DEC19" should be:
    91        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
    92        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 731          | 10000          | 1             |
    93      When the parties place the following orders with ticks:
    94        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    95        | trader4 | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    96        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    97  
    98      And the market data for the market "ETH/DEC19" should be:
    99        | mark price | trading mode            | target stake | supplied stake | open interest |
   100        | 150        | TRADING_MODE_CONTINUOUS | 731          | 10000          | 1             |
   101      When the parties place the following orders with ticks:
   102        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   103        | trader5 | ETH/DEC19 | buy  | 290    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   104  
   105      Then the parties should have the following account balances:
   106        | party   | asset | market id | margin | general |
   107        | trader5 | USD   | ETH/DEC19 | 0      | 0       |
   108  
   109      When the parties place the following orders with ticks:
   110        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   111        | trader3 | ETH/DEC19 | buy  | 290    | 120   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2 |
   112  
   113      And the parties place the following orders with ticks:
   114        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   115        | trader4 | ETH/DEC19 | sell | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   116        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   117  
   118      Then the insurance pool balance should be "4027" for the market "ETH/DEC19"
   119      And the global insurance pool balance should be "0" for the asset "USD"
   120      And the liquidity provider fee shares for the market "ETH/DEC19" should be:
   121        | party   | equity like share | average entry valuation |
   122        | lpprov1 | 0.9               | 9000                    |
   123        | lpprov2 | 0.1               | 10000                   |
   124  
   125  # make LP commitment while market is still pending
   126      And the parties submit the following liquidity provision:
   127        | id  | party   | market id | commitment amount | fee | lp type    |
   128        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | submission |
   129        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | submission |
   130        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   131        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   132        | lp3 | lpprov3 | ETH/DEC21 | 8000              | 0.1 | submission |
   133        | lp3 | lpprov3 | ETH/DEC21 | 8000              | 0.1 | submission |
   134  
   135      # check LP bond account after LP commitment submission
   136      Then the parties should have the following account balances:
   137        | party   | asset | market id | margin | general     | bond |
   138        | lpprov1 | USD   | ETH/DEC19 | 0      | 1999989000  | 9000 |
   139        | lpprov2 | USD   | ETH/DEC20 | 0      | 19999991000 | 8000 |
   140        | lpprov3 | USD   | ETH/DEC21 | 0      | 19999992000 | 8000 |
   141  
   142  # market ETH/DEC19 is not settled yet, it still active
   143      And the insurance pool balance should be "4027" for the market "ETH/DEC19"
   144      And the insurance pool balance should be "0" for the market "ETH/DEC20"
   145      And the global insurance pool balance should be "0" for the asset "USD"
   146  
   147      When the successor market "ETH/DEC20" is enacted
   148      When the successor market "ETH/DEC21" is enacted
   149  
   150      Then the parties place the following orders:
   151        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference    |
   152        | trader1 | ETH/DEC20 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |              |
   153        | trader1 | ETH/DEC20 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |              |
   154        | trader1 | ETH/DEC21 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC | order1-DEC21 |
   155        | trader1 | ETH/DEC21 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC | order2-DEC21 |
   156        | trader1 | ETH/DEC20 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |              |
   157        | trader2 | ETH/DEC20 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |              |
   158      When the opening auction period ends for market "ETH/DEC20"
   159      Then the market data for the market "ETH/DEC20" should be:
   160        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   161        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 82           | 10000          | 1             |
   162  
   163      And the last market state should be "STATE_REJECTED" for the market "ETH/DEC21"
   164  
   165      #check assets held to support trader1's orders in market ETH/DEC21 is released
   166      Then the parties should have the following account balances:
   167        | party   | asset | market id | margin | general |
   168        | trader1 | USD   | ETH/DEC20 | 122    | 2000288 |
   169        | trader1 | USD   | ETH/DEC21 | 0      | 2000288 |
   170  
   171      #check all the orders in market ETH/DEC21 is canceled
   172      And the orders should have the following status:
   173        | party   | reference    | status         |
   174        | trader1 | order1-DEC21 | STATUS_STOPPED |
   175        | trader1 | order2-DEC21 | STATUS_STOPPED |
   176  
   177      And the insurance pool balance should be "1611" for the market "ETH/DEC19"
   178      And the insurance pool balance should be "2416" for the market "ETH/DEC20"
   179      And the insurance pool balance should be "0" for the market "ETH/DEC21"
   180      And the global insurance pool balance should be "0" for the asset "USD"
   181  
   182      # check LP account is released after the market ETH/DEC21 is rejceted
   183      Then the parties should have the following account balances:
   184        | party   | asset | market id | margin | general     |
   185        | lpprov3 | USD   | ETH/DEC21 | 0      | 20000000000 |
   186      When the network moves ahead "2" blocks
   187  
   188      # this is from ETH/DEC19 market
   189      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   190        | party   | equity like share | average entry valuation |
   191        | lpprov1 | 0.2               | 9000                    |
   192        | lpprov2 | 0.8               | 10000                   |
   193  
   194      And the accumulated liquidity fees should be "0" for the market "ETH/DEC20"
   195  
   196      When the parties submit the following liquidity provision:
   197        | id  | party   | market id | commitment amount | fee | lp type   |
   198        | lp2 | lpprov2 | ETH/DEC19 | 2000              | 0.1 | amendment |
   199        | lp2 | lpprov2 | ETH/DEC19 | 2000              | 0.1 | amendment |
   200      When the network moves ahead "2" blocks
   201      Then the liquidity provider fee shares for the market "ETH/DEC19" should be:
   202        | party   | equity like share | average entry valuation |
   203        | lpprov1 | 0.9               | 9000                    |
   204        | lpprov2 | 0.1               | 10000                   |
   205      When the oracles broadcast data signed with "0xCAFECAFE1":
   206        | name               | value |
   207        | trading.terminated | true  |
   208        | prices.ETH.value   | 976   |
   209      Then the market state should be "STATE_SETTLED" for the market "ETH/DEC19"
   210      When the network moves ahead "2" blocks
   211  
   212      And the parties submit the following liquidity provision:
   213        | id  | party   | market id | commitment amount | fee | lp type   |
   214        | lp1 | lpprov1 | ETH/DEC20 | 3000              | 0.1 | amendment |
   215        | lp1 | lpprov1 | ETH/DEC20 | 3000              | 0.1 | amendment |
   216      When the network moves ahead "2" blocks
   217  
   218      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   219        | party   | equity like share  | average entry valuation |
   220        | lpprov1 | 0.2727272727272727 | 9666.6666666666666667   |
   221        | lpprov2 | 0.7272727272727273 | 10000                   |
   222      When the network moves ahead "1" blocks
   223      Then the insurance pool balance should be "0" for the market "ETH/DEC19"
   224      And the insurance pool balance should be "2416" for the market "ETH/DEC20"
   225      And the global insurance pool balance should be "9338" for the asset "USD"
   226  
   227    @SuccessorMarketSimple @Liquidation
   228    Scenario: 002 Successor market enacted with parent market still active, ELS is copied over and both states can change independently. 0042-LIQF-031, 0042-LIQF-048, 0042-LIQF-033
   229      Given the markets:
   230        | id        | quote name | asset | risk model                | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | decimal places | position decimal places | parent market id | insurance pool fraction | successor auction | sla params |
   231        | ETH/DEC19 | ETH        | USD   | lognormal-risk-model-fish | margin-calculator-1       | 1                | default-none | default-none     | ethDec19Oracle         | 0.1                    | 0                         | 0              | 0                       |                  |                         |                   | SLA        |
   232        | ETH/DEC20 | ETH        | USD   | default-st-risk-model     | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.1                    | 0                         | 0              | 0                       | ETH/DEC19        | 0.6                     | 10                | SLA        |
   233      And the following network parameters are set:
   234        | name                                               | value |
   235        | market.liquidity.providersFeeCalculationTimeStep | 5s    |
   236      And the parties submit the following liquidity provision:
   237        | id  | party   | market id | commitment amount | fee | lp type    |
   238        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
   239        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
   240        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
   241        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
   242      And the parties place the following orders:
   243        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   244        | trader1 | ETH/DEC19 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   245        | trader1 | ETH/DEC19 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   246        | trader1 | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   247        | trader2 | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   248      When the opening auction period ends for market "ETH/DEC19"
   249      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   250      Then the market data for the market "ETH/DEC19" should be:
   251        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   252        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 731          | 10000          | 1             |
   253      When the parties place the following orders with ticks:
   254        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
   255        | trader4 | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   256        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
   257  
   258      And the market data for the market "ETH/DEC19" should be:
   259        | mark price | trading mode            | target stake | supplied stake | open interest |
   260        | 150        | TRADING_MODE_CONTINUOUS | 731          | 10000          | 1             |
   261      When the parties place the following orders with ticks:
   262        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   263        | trader5 | ETH/DEC19 | buy  | 290    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   264  
   265      Then the parties should have the following account balances:
   266        | party   | asset | market id | margin | general |
   267        | trader5 | USD   | ETH/DEC19 | 0      | 0       |
   268  
   269      When the parties place the following orders with ticks:
   270        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   271        | trader3 | ETH/DEC19 | buy  | 290    | 120   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2 |
   272  
   273      When the parties place the following orders with ticks:
   274        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   275        | trader4 | ETH/DEC19 | sell | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   276        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   277  
   278      Then the insurance pool balance should be "4027" for the market "ETH/DEC19"
   279      And the global insurance pool balance should be "0" for the asset "USD"
   280      And the liquidity provider fee shares for the market "ETH/DEC19" should be:
   281        | party   | equity like share | average entry valuation |
   282        | lpprov1 | 0.9               | 9000                    |
   283        | lpprov2 | 0.1               | 10000                   |
   284  
   285  # make LP commitment while market is still pending
   286      And the parties submit the following liquidity provision:
   287        | id  | party   | market id | commitment amount | fee | lp type    |
   288        | lp1 | lpprov1 | ETH/DEC20 | 4000              | 0.1 | submission |
   289        | lp1 | lpprov1 | ETH/DEC20 | 4000              | 0.1 | submission |
   290        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   291        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   292  
   293      Then the oracles broadcast data signed with "0xCAFECAFE1":
   294        | name               | value |
   295        | trading.terminated | true  |
   296        | prices.ETH.value   | 975   |
   297  
   298      # pass succession window
   299      When the network moves ahead "1" blocks
   300      Then the successor market "ETH/DEC20" is enacted
   301  
   302      And the parties place the following orders:
   303        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   304        | trader1 | ETH/DEC20 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   305        | trader1 | ETH/DEC20 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   306        | trader1 | ETH/DEC20 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   307        | trader2 | ETH/DEC20 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   308  
   309      # make LP commitment change  while market is still pending
   310      And the parties submit the following liquidity provision:
   311        | id  | party   | market id | commitment amount | fee | lp type   |
   312        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | amendment |
   313        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | amendment |
   314      When the network moves ahead "2" blocks
   315      When the opening auction period ends for market "ETH/DEC20"
   316      Then the market data for the market "ETH/DEC20" should be:
   317        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   318        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 82           | 10000          | 1             |
   319  
   320      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   321      And the insurance pool balance should be "7052" for the market "ETH/DEC20"
   322      And the global insurance pool balance should be "4702" for the asset "USD"
   323  
   324  #this is from ETH/DEC19 market
   325      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   326        | party   | equity like share  | average entry valuation |
   327        | lpprov1 | 0.3333333333333333 | 9000                    |
   328        | lpprov2 | 0.6666666666666667 | 11750                   |
   329  
   330      And the accumulated liquidity fees should be "0" for the market "ETH/DEC20"
   331  
   332      And the parties submit the following liquidity provision:
   333        | id  | party   | market id | commitment amount | fee | lp type   |
   334        | lp1 | lpprov1 | ETH/DEC20 | 3000              | 0.1 | amendment |
   335        | lp1 | lpprov1 | ETH/DEC20 | 3000              | 0.1 | amendment |
   336      When the network moves ahead "2" blocks
   337  
   338      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   339        | party   | equity like share  | average entry valuation |
   340        | lpprov1 | 0.2727272727272727 | 9000                    |
   341        | lpprov2 | 0.7272727272727273 | 11750                   |
   342  
   343  
   344    @SuccessorMarketActive @NoPerp @Liquidation
   345    Scenario: 003 Enact a successor market while the parent is still active. Pending successors get rejected
   346      Given the markets:
   347        | id        | quote name | asset | risk model                | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | decimal places | position decimal places | parent market id | insurance pool fraction | successor auction | sla params |
   348        | ETH/DEC19 | ETH        | USD   | lognormal-risk-model-fish | margin-calculator-1       | 1                | default-none | default-none     | ethDec19Oracle         | 0.1                    | 0                         | 0              | 0                       |                  |                         |                   | SLA        |
   349        | ETH/DEC20 | ETH        | USD   | default-st-risk-model     | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.1                    | 0                         | 0              | 0                       | ETH/DEC19        | 0.6                     | 10                | SLA        |
   350        | ETH/DEC21 | ETH        | USD   | default-st-risk-model     | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.1                    | 0                         | 0              | 0                       | ETH/DEC19        | 0.1                     | 10                | SLA        |
   351      And the following network parameters are set:
   352        | name                                               | value |
   353        | market.liquidity.providersFeeCalculationTimeStep | 5s    |
   354      And the parties submit the following liquidity provision:
   355        | id  | party   | market id | commitment amount | fee | lp type    |
   356        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
   357        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
   358        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
   359        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
   360      And the parties place the following orders:
   361        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   362        | trader1 | ETH/DEC19 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   363        | trader1 | ETH/DEC19 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   364        | trader1 | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   365        | trader2 | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   366      When the opening auction period ends for market "ETH/DEC19"
   367      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   368      Then the market data for the market "ETH/DEC19" should be:
   369        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   370        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 731          | 10000          | 1             |
   371      When the parties place the following orders with ticks:
   372        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
   373        | trader4 | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   374        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
   375  
   376      And the market data for the market "ETH/DEC19" should be:
   377        | mark price | trading mode            | target stake | supplied stake | open interest |
   378        | 150        | TRADING_MODE_CONTINUOUS | 731          | 10000          | 1             |
   379      When the parties place the following orders with ticks:
   380        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   381        | trader5 | ETH/DEC19 | buy  | 290    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   382  
   383      Then the parties should have the following account balances:
   384        | party   | asset | market id | margin | general |
   385        | trader5 | USD   | ETH/DEC19 | 0      | 0       |
   386  
   387      When the parties place the following orders with ticks:
   388        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   389        | trader3 | ETH/DEC19 | buy  | 290    | 120   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2 |
   390  
   391      When the parties place the following orders with ticks:
   392        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   393        | trader4 | ETH/DEC19 | sell | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   394        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   395  
   396      And the insurance pool balance should be "4027" for the market "ETH/DEC19"
   397      And the global insurance pool balance should be "0" for the asset "USD"
   398      And the liquidity provider fee shares for the market "ETH/DEC19" should be:
   399        | party   | equity like share | average entry valuation |
   400        | lpprov1 | 0.9               | 9000                    |
   401        | lpprov2 | 0.1               | 10000                   |
   402  
   403  # make LP commitment while market is still pending
   404      And the parties submit the following liquidity provision:
   405        | id  | party   | market id | commitment amount | fee | lp type    |
   406        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | submission |
   407        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | submission |
   408        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   409        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   410  
   411  #market ETH/DEC19 is not settled yet, it still active
   412  
   413      And the insurance pool balance should be "4027" for the market "ETH/DEC19"
   414      And the insurance pool balance should be "0" for the market "ETH/DEC20"
   415      And the global insurance pool balance should be "0" for the asset "USD"
   416      When the successor market "ETH/DEC20" is enacted
   417  
   418      Then the parties place the following orders:
   419        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   420        | trader1 | ETH/DEC20 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   421        | trader1 | ETH/DEC20 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   422        | trader1 | ETH/DEC20 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   423        | trader2 | ETH/DEC20 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   424      When the opening auction period ends for market "ETH/DEC20"
   425      Then the last market state should be "STATE_REJECTED" for the market "ETH/DEC21"
   426      And the market data for the market "ETH/DEC20" should be:
   427        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   428        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 82           | 10000          | 1             |
   429      And the insurance pool balance should be "1611" for the market "ETH/DEC19"
   430      And the insurance pool balance should be "2416" for the market "ETH/DEC20"
   431      And the global insurance pool balance should be "0" for the asset "USD"
   432  
   433      # this is from ETH/DEC19 market
   434      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   435        | party   | equity like share | average entry valuation |
   436        | lpprov1 | 0.2               | 9000                    |
   437        | lpprov2 | 0.8               | 10000                   |
   438  
   439      And the accumulated liquidity fees should be "0" for the market "ETH/DEC20"
   440  
   441      When the parties submit the following liquidity provision:
   442        | id  | party   | market id | commitment amount | fee | lp type   |
   443        | lp2 | lpprov2 | ETH/DEC19 | 2000              | 0.1 | amendment |
   444        | lp2 | lpprov2 | ETH/DEC19 | 2000              | 0.1 | amendment |
   445      When the network moves ahead "2" blocks
   446      Then the liquidity provider fee shares for the market "ETH/DEC19" should be:
   447        | party   | equity like share  | average entry valuation |
   448        | lpprov1 | 0.8181818181818182 | 9000                    |
   449        | lpprov2 | 0.1818181818181818 | 10500                   |
   450      When the oracles broadcast data signed with "0xCAFECAFE1":
   451        | name               | value |
   452        | trading.terminated | true  |
   453        | prices.ETH.value   | 976   |
   454      Then the market state should be "STATE_SETTLED" for the market "ETH/DEC19"
   455      Then the market state should be "STATE_ACTIVE" for the market "ETH/DEC20"
   456  
   457      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   458        | party   | equity like share | average entry valuation |
   459        | lpprov1 | 0.2               | 9000                    |
   460        | lpprov2 | 0.8               | 10000                   |
   461      When the network moves ahead "2" blocks
   462  
   463      And the parties submit the following liquidity provision:
   464        | id  | party   | market id | commitment amount | fee | lp type   |
   465        | lp1 | lpprov1 | ETH/DEC20 | 12000             | 0.1 | amendment |
   466        | lp1 | lpprov1 | ETH/DEC20 | 12000             | 0.1 | amendment |
   467      When the network moves ahead "2" blocks
   468  
   469      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   470        | party   | equity like share | average entry valuation |
   471        | lpprov1 | 0.2               | 9000                    |
   472        | lpprov2 | 0.8               | 10000                   |
   473      When the network moves ahead "1" blocks
   474      Then the insurance pool balance should be "0" for the market "ETH/DEC19"
   475      And the insurance pool balance should be "2416" for the market "ETH/DEC20"
   476      And the global insurance pool balance should be "9338" for the asset "USD"
   477  
   478  
   479    @SuccessorMarketExpires2 @Liquidation
   480    Scenario: 004 Enact a successor market while the parent is still active. Pending successors get rejected
   481      Given the markets:
   482        | id        | quote name | asset | risk model                | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | decimal places | position decimal places | parent market id | insurance pool fraction | successor auction | sla params |
   483        | ETH/DEC19 | ETH        | USD   | lognormal-risk-model-fish | margin-calculator-1       | 1                | default-none | default-none     | ethDec19Oracle         | 0.1                    | 0                         | 0              | 0                       |                  |                         |                   | SLA        |
   484        | ETH/DEC20 | ETH        | USD   | default-st-risk-model     | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.1                    | 0                         | 0              | 0                       | ETH/DEC19        | 0.8                     | 10                | SLA        |
   485      And the following network parameters are set:
   486        | name                                               | value |
   487        | market.liquidity.providersFeeCalculationTimeStep | 5s    |
   488        | market.liquidity.successorLaunchWindowLength       | 1s    |
   489  
   490      And the parties submit the following liquidity provision:
   491        | id  | party   | market id | commitment amount | fee | lp type    |
   492        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
   493        | lp1 | lpprov1 | ETH/DEC19 | 9000              | 0.1 | submission |
   494        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
   495        | lp2 | lpprov2 | ETH/DEC19 | 1000              | 0.1 | submission |
   496      And the parties place the following orders:
   497        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   498        | trader1 | ETH/DEC19 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   499        | trader1 | ETH/DEC19 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   500        | trader1 | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   501        | trader2 | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   502      When the opening auction period ends for market "ETH/DEC19"
   503      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   504      Then the market data for the market "ETH/DEC19" should be:
   505        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   506        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 731          | 10000          | 1             |
   507      When the parties place the following orders with ticks:
   508        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
   509        | trader4 | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   510        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
   511  
   512      And the market data for the market "ETH/DEC19" should be:
   513        | mark price | trading mode            | target stake | supplied stake | open interest |
   514        | 150        | TRADING_MODE_CONTINUOUS | 731          | 10000          | 1             |
   515      When the parties place the following orders with ticks:
   516        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   517        | trader5 | ETH/DEC19 | buy  | 290    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   518  
   519      Then the parties should have the following account balances:
   520        | party   | asset | market id | margin | general |
   521        | trader5 | USD   | ETH/DEC19 | 0      | 0       |
   522  
   523      When the parties place the following orders with ticks:
   524        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   525        | trader3 | ETH/DEC19 | buy  | 290    | 120   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2 |
   526  
   527      When the parties place the following orders with ticks:
   528        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   529        | trader4 | ETH/DEC19 | sell | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   530        | trader3 | ETH/DEC19 | buy  | 1      | 140   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   531  
   532      Then the insurance pool balance should be "4027" for the market "ETH/DEC19"
   533      Then the insurance pool balance should be "0" for the market "ETH/DEC20"
   534      And the global insurance pool balance should be "0" for the asset "USD"
   535      And the liquidity provider fee shares for the market "ETH/DEC19" should be:
   536        | party   | equity like share | average entry valuation |
   537        | lpprov1 | 0.9               | 9000                    |
   538        | lpprov2 | 0.1               | 10000                   |
   539  
   540      And the insurance pool balance should be "4027" for the market "ETH/DEC19"
   541      And the insurance pool balance should be "0" for the market "ETH/DEC20"
   542      And the global insurance pool balance should be "0" for the asset "USD"
   543  
   544      When the oracles broadcast data signed with "0xCAFECAFE1":
   545        | name               | value |
   546        | trading.terminated | true  |
   547        | prices.ETH.value   | 140   |
   548      Then the market state should be "STATE_SETTLED" for the market "ETH/DEC19"
   549      And the successor market "ETH/DEC20" is enacted
   550      When the network moves ahead "5" blocks
   551      Then the insurance pool balance should be "0" for the market "ETH/DEC19"
   552      Then the insurance pool balance should be "0" for the market "ETH/DEC20"
   553      And the global insurance pool balance should be "11754" for the asset "USD"
   554  
   555  # make LP commitment while market is still pending
   556      Then the parties submit the following liquidity provision:
   557        | id  | party   | market id | commitment amount | fee | lp type    |
   558        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | submission |
   559        | lp1 | lpprov1 | ETH/DEC20 | 2000              | 0.1 | submission |
   560        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   561        | lp2 | lpprov2 | ETH/DEC20 | 8000              | 0.1 | submission |
   562  
   563      And the parties place the following orders:
   564        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   565        | trader1 | ETH/DEC20 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   566        | trader1 | ETH/DEC20 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   567        | trader1 | ETH/DEC20 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   568        | trader2 | ETH/DEC20 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
   569      When the opening auction period ends for market "ETH/DEC20"
   570      Then the market data for the market "ETH/DEC20" should be:
   571        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   572        | 150        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 82           | 10000          | 1             |
   573      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   574      And the insurance pool balance should be "0" for the market "ETH/DEC20"
   575      And the global insurance pool balance should be "11754" for the asset "USD"    
   576  
   577      # this is from ETH/DEC19 market
   578      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   579        | party   | equity like share | average entry valuation |
   580        | lpprov1 | 0.2               | 2000                    |
   581        | lpprov2 | 0.8               | 10000                   |
   582  
   583      And the accumulated liquidity fees should be "0" for the market "ETH/DEC20"
   584  
   585      And the parties submit the following liquidity provision:
   586        | id  | party   | market id | commitment amount | fee | lp type   |
   587        | lp1 | lpprov1 | ETH/DEC20 | 3000              | 0.1 | amendment |
   588        | lp1 | lpprov1 | ETH/DEC20 | 3000              | 0.1 | amendment |
   589      When the network moves ahead "5" blocks
   590  
   591      And the liquidity provider fee shares for the market "ETH/DEC20" should be:
   592        | party   | equity like share  | average entry valuation |
   593        | lpprov1 | 0.2727272727272727 | 5000                    |
   594        | lpprov2 | 0.7272727272727273 | 10000                   |
   595      When the network moves ahead "1" blocks
   596      Then the insurance pool balance should be "0" for the market "ETH/DEC19"
   597      And the insurance pool balance should be "0" for the market "ETH/DEC20"
   598      And the global insurance pool balance should be "11754" for the asset "USD"