code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/0053-PERP-024_LossSocialisation.feature (about)

     1  Feature: Test funding payment triggering closeout for Perps market
     2  
     3    Background:
     4  
     5      And the perpetual oracles from "0xCAFECAFE1":
     6        | name        | asset | settlement property | settlement type | schedule property | schedule type  | margin funding factor | interest rate | clamp lower bound | clamp upper bound | quote name | settlement decimals |
     7        | perp-oracle | USD   | perp.ETH.value      | TYPE_INTEGER    | perp.funding.cue  | TYPE_TIMESTAMP | 0.5                   | 0.05          | 0.1               | 0.9               | ETH        | 18                  |
     8      And the liquidity sla params named "SLA":
     9        | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    10        | 1.0         | 0.5                          | 1                             | 1.0                    |
    11  
    12      And the markets:
    13        | id        | quote name | asset | risk model                  | margin calculator         | auction duration | fees         | price monitoring | data source config | linear slippage factor | quadratic slippage factor | position decimal places | market type | sla params      |
    14        | ETH/DEC19 | ETH        | USD   | default-simple-risk-model-3 | default-margin-calculator | 1                | default-none | default-none     | perp-oracle        | 0.25                   | 0                         | -3                      | perp        | default-futures |
    15      And the initial insurance pool balance is "200" for all the markets
    16      And the following network parameters are set:
    17        | name                           | value |
    18        | market.auction.minimumDuration | 1     |
    19        | limits.markets.maxPeggedOrders | 2     |
    20  
    21    @Perpetual @Liquidation
    22    Scenario: (0053-PERP-024) Funding payment triggering loss socialization
    23      Given the following network parameters are set:
    24        | name                                    | value |
    25        | network.markPriceUpdateMaximumFrequency | 5s    |
    26      And the parties deposit on asset's general account the following amount:
    27        | party  | asset | amount    |
    28        | party1 | USD   | 10000000  |
    29        | party2 | USD   | 10000000  |
    30        | party3 | USD   | 10000000  |
    31        | aux    | USD   | 100000000 |
    32        | aux2   | USD   | 1695000   |
    33        | lpprov | USD   | 100000000 |
    34  
    35      When the parties submit the following liquidity provision:
    36        | id  | party  | market id | commitment amount | fee   | lp type    |
    37        | lp1 | lpprov | ETH/DEC19 | 10000000          | 0.001 | submission |
    38        | lp1 | lpprov | ETH/DEC19 | 10000000          | 0.001 | submission |
    39      And the parties place the following pegged iceberg orders:
    40        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
    41        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 1      |
    42        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 1      |
    43  
    44      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    45      When the parties place the following orders:
    46        | party | market id | side | volume | price | resulting trades | type       | tif     |
    47        | aux   | ETH/DEC19 | buy  | 1      | 49    | 0                | TYPE_LIMIT | TIF_GTC |
    48        | aux   | ETH/DEC19 | sell | 1      | 5001  | 0                | TYPE_LIMIT | TIF_GTC |
    49        | aux2  | ETH/DEC19 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    50        | aux   | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    51  
    52      And the market data for the market "ETH/DEC19" should be:
    53        | target stake | supplied stake |
    54        | 1100000      | 10000000       |
    55      Then the opening auction period ends for market "ETH/DEC19"
    56      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    57      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
    58  
    59      # back sure we end the block so we're in a new one after opening auction
    60      When the network moves ahead "1" blocks
    61  
    62      When the parties place the following orders:
    63        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    64        | party1 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    65        | party2 | ETH/DEC19 | buy  | 1      | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
    66  
    67      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
    68      When the parties place the following orders:
    69        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    70        | party1 | ETH/DEC19 | sell | 1      | 1200  | 0                | TYPE_LIMIT | TIF_GTC |
    71  
    72      When the parties place the following orders:
    73        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    74        | party3 | ETH/DEC19 | buy  | 1      | 1200  | 1                | TYPE_LIMIT | TIF_GTC |
    75  
    76      And the market data for the market "ETH/DEC19" should be:
    77        | mark price | trading mode            | target stake | supplied stake | open interest |
    78        | 1000       | TRADING_MODE_CONTINUOUS | 3300000      | 10000000       | 3             |
    79      # send in external data to the perpetual market, it should not change anything and a MTM should not happen
    80      When the network moves ahead "1" blocks
    81      And the mark price should be "1000" for the market "ETH/DEC19"
    82  
    83      When time is updated to "2021-02-10T23:04:12Z"
    84      Then system unix time is "1612998252"
    85  
    86      When the oracles broadcast data with block time signed with "0xCAFECAFE1":
    87        | name             | value                  | time offset |
    88        | perp.ETH.value   | 3000000000000000000000 | 0s          |
    89        | perp.funding.cue | 1612998252             | 0s          |
    90      
    91      When time is updated to "2021-08-12T11:04:12Z"
    92      Then system unix time is "1628766252"
    93      
    94      When the network moves ahead "4" blocks
    95  
    96      #MTM for mark price 1000 to 1200
    97      And the following transfers should happen:
    98        | from   | to     | from account            | to account              | market id | amount | asset |
    99        | party1 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 200000 | USD   |
   100        | aux    | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 200000 | USD   |
   101        | market | aux2   | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 200000 | USD   |
   102        | market | party2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 200000 | USD   |
   103  
   104      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
   105  
   106      When the parties place the following orders:
   107        | party | market id | side | volume | price | resulting trades | type       | tif     |
   108        | aux   | ETH/DEC19 | sell | 1      | 2001  | 0                | TYPE_LIMIT | TIF_GTC |
   109        | aux2  | ETH/DEC19 | buy  | 1      | 2001  | 1                | TYPE_LIMIT | TIF_GTC |
   110  
   111      # update linear slippage factor more in line with what book-based slippage used to be
   112      And the markets are updated:
   113          | id          | linear slippage factor |
   114          | ETH/DEC19   | 4                      |
   115      # Allow network close-outs to kick in
   116      Then the network moves ahead "1" blocks
   117  
   118      And the mark price should be "1200" for the market "ETH/DEC19"
   119  
   120      #delta_t = 0.5
   121      When the oracles broadcast data with block time signed with "0xCAFECAFE1":
   122        | name             | value                  | time offset |
   123        | perp.ETH.value   | 3000000000000000000000 | 0s          |
   124        | perp.funding.cue | 1628766252             | 0s          |
   125  
   126      #funding payment = s_twap * delta_t * interest_rate = 3000*0.5*0.05 = 150000
   127      And the following transfers should happen:
   128        | from   | to     | from account            | to account              | market id | amount | asset |
   129        | aux2   | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 150000 | USD   |
   130        | party2 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 75000  | USD   |
   131        | party3 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 75000  | USD   |
   132        | market | aux    | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 150000 | USD   |
   133        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 150000 | USD   |
   134  
   135      Then the parties should have the following margin levels:
   136        | party | market id | maintenance | initial |
   137        | aux2  | ETH/DEC19 | 0           | 0       |
   138      #loss socialisaton happened
   139      And the insurance pool balance should be "1563199" for the market "ETH/DEC19"
   140      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
   141