code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/0019-MCAL_fundingMargin5.feature (about)

     1  Feature: check when settlement data precision is different/equal to the settlement asset precision, and also check decimal on the market with different market/position/asset decimal
     2  
     3    Background:
     4      Given the following assets are registered:
     5        | id  | decimal places |
     6        | USD | 2              |
     7  
     8      And the perpetual oracles from "0xCAFECAFE1":
     9        | 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 |
    10        | perp-oracle-1 | USD   | perp.ETH.value      | TYPE_INTEGER    | perp.funding.cue  | TYPE_TIMESTAMP | 0.5                   | 0.05          | 0.1               | 0.5               | ETH        | 5                   |
    11      And the perpetual oracles from "0xCAFECAFE2":
    12        | 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 |
    13        | perp-oracle-2 | USD   | perp.ETH.value      | TYPE_INTEGER    | perp.funding.cue  | TYPE_TIMESTAMP | 0.5                   | 0.05          | 0.1               | 0.5               | ETH        | 2                   |
    14      And the perpetual oracles from "0xCAFECAFE3":
    15        | 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 |
    16        | perp-oracle-3 | USD   | perp.ETH.value      | TYPE_INTEGER    | perp.funding.cue  | TYPE_TIMESTAMP | 0.5                   | 0.05          | 0.1               | 0.5               | ETH        | 1                   |
    17      And the liquidity sla params named "SLA":
    18        | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    19        | 1.0         | 0.5                          | 1                             | 1.0                    |
    20  
    21      And the markets:
    22        | 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      |
    23        | ETH/DEC19 | ETH        | USD   | default-simple-risk-model-3 | default-margin-calculator | 1                | default-none | default-none     | perp-oracle-1      | 0.218875               | 0                         | -1                      | perp        | default-futures |
    24      And the following network parameters are set:
    25        | name                           | value |
    26        | market.auction.minimumDuration | 1     |
    27        | limits.markets.maxPeggedOrders | 2     |
    28  
    29    @Perpetual @PerpUpdate
    30    Scenario: 0070-MKTD-018, 0070-MKTD-019, 0070-MKTD-020
    31      Given the following network parameters are set:
    32        | name                                    | value |
    33        | network.markPriceUpdateMaximumFrequency | 5s    |
    34      And the parties deposit on asset's general account the following amount:
    35        | party  | asset | amount     |
    36        | party1 | USD   | 1000000000 |
    37        | party2 | USD   | 100000000  |
    38        | party3 | USD   | 100000000  |
    39        | aux    | USD   | 300000000  |
    40        | aux2   | USD   | 300000000  |
    41        | lp1    | USD   | 500000000  |
    42        | lp2    | USD   | 500000000  |
    43        | lp3    | USD   | 500000000  |
    44  
    45      When the parties submit the following liquidity provision:
    46        | id  | party | market id | commitment amount | fee   | lp type    |
    47        | lp1 | lp1   | ETH/DEC19 | 1200000           | 0.001 | submission |
    48  
    49      Then the parties place the following pegged iceberg orders:
    50        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | reference |
    51        | lp1   | ETH/DEC19 | 20        | 1                    | buy  | BID              | 50     | 1      | lp-buy-1  |
    52        | lp1   | ETH/DEC19 | 20        | 1                    | sell | ASK              | 50     | 1      | lp-sell-1 |
    53      And the parties place the following orders:
    54        | party | market id | side | volume | price | resulting trades | type       | tif     |
    55        | aux   | ETH/DEC19 | buy  | 1      | 849   | 0                | TYPE_LIMIT | TIF_GTC |
    56        | aux   | ETH/DEC19 | sell | 1      | 2001  | 0                | TYPE_LIMIT | TIF_GTC |
    57        | aux2  | ETH/DEC19 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    58        | aux   | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    59  
    60      When the opening auction period ends for market "ETH/DEC19"
    61      Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    62  
    63      # back sure we end the block so we're in a new one after opening auction
    64      When the network moves ahead "1" blocks
    65  
    66      And the parties place the following orders:
    67        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    68        | party1 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    69        | party2 | ETH/DEC19 | buy  | 1      | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
    70  
    71      Then the parties should have the following account balances:
    72        | party  | asset | market id | margin  | general   |
    73        | party1 | USD   | ETH/DEC19 | 120000  | 999880000 |
    74        | party2 | USD   | ETH/DEC19 | 132000  | 99867000  |
    75        | lp1    | USD   | ETH/DEC19 | 6600000 | 492200000 |
    76  
    77      When the parties place the following orders:
    78        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    79        | party1 | ETH/DEC19 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
    80        | party3 | ETH/DEC19 | buy  | 1      | 2000  | 1                | TYPE_LIMIT | TIF_GTC |
    81  
    82      When time is updated to "2021-02-11T16:35:24Z"
    83      Then system unix time is "1613061324"
    84  
    85      When the oracles broadcast data with block time signed with "0xCAFECAFE1":
    86        | name             | value      | time offset |
    87        | perp.funding.cue | 1613061324 | 0s          |
    88      And the network moves ahead "5" blocks
    89  
    90      When time is updated to "2021-08-12T11:04:12Z"
    91      Then system unix time is "1628766252"
    92  
    93      Then the oracles broadcast data with block time signed with "0xCAFECAFE1":
    94        | name             | value      | time offset |
    95        | perp.ETH.value   | 300000000  | 0s          |
    96        | perp.funding.cue | 1628766252 | 0s          |
    97      #1628766252 is half year after the first oracle time
    98  
    99      And the following transfers should happen:
   100        | from   | to     | from account            | to account              | market id | amount | asset |
   101        | aux2   | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 74700  | USD   |
   102        | party2 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 74700  | USD   |
   103        | party3 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 74700  | USD   |
   104        | market | aux    | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 74700  | USD   |
   105        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 149400 | USD   |
   106  
   107      When the network moves ahead "5" blocks
   108  
   109      Then the markets are updated:
   110        | id        | data source config | linear slippage factor | quadratic slippage factor |
   111        | ETH/DEC19 | perp-oracle-2      | 0.25                   | 0                         |
   112  
   113      When time is updated to "2021-08-12T11:04:30Z"
   114      Then system unix time is "1628766270"
   115  
   116      And the oracles broadcast data with block time signed with "0xCAFECAFE2":
   117        | name             | value      | time offset |
   118        | perp.funding.cue | 1628766270 | 0s          |
   119        | perp.ETH.value   | 350000000  | 0s          |
   120  
   121      When time is updated to "2024-10-12T20:51:10Z"
   122      Then system unix time is "1728766270"
   123  
   124      Then the oracles broadcast data with block time signed with "0xCAFECAFE2":
   125        | name             | value      | time offset |
   126        | perp.funding.cue | 1728766270 | 0s          |
   127  
   128      And the following funding period events should be emitted:
   129        | start      | end        | internal twap | external twap | funding payment |
   130        | 1628766270 | 1728766270 | 200000        | 350000000     | -174800000      |
   131  
   132      # funding loss, win, margin excess transfers:
   133      And the following transfers should happen:
   134        | from   | to     | from account            | to account              | market id | amount    | asset | type | 
   135        | aux    | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 1080000   | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 
   136        | aux    | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 297994700 | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 
   137        | party1 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 1680000   | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 
   138        | party1 | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 997469400 | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 
   139        | market | party2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 432741366 | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN  | 
   140        | market | party3 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 432741368 | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN  | 
   141        | market | aux2   | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 432741366 | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN  | 
   142        | aux2   | aux2   | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_GENERAL    | ETH/DEC19 | 432711486 | USD   | TRANSFER_TYPE_MARGIN_HIGH             | 
   143        | party2 | party2 | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_GENERAL    | ETH/DEC19 | 432711486 | USD   | TRANSFER_TYPE_MARGIN_HIGH             | 
   144        | party3 | party3 | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_GENERAL    | ETH/DEC19 | 432711488 | USD   | TRANSFER_TYPE_MARGIN_HIGH             |