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

     1  Feature: Test funding margin for Perps market
     2  
     3    @Perpetual
     4    Scenario: (0019-MCAL-026 - cross margin, 0019-MCAL-053 - isolated margin) check funding margin for Perps market when clumps are 0 and 0.9, 0070-MKTD-017
     5      Given the following assets are registered:
     6        | id  | decimal places |
     7        | USD | 3              |
     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 | USD   | perp.ETH.value      | TYPE_INTEGER    | perp.funding.cue  | TYPE_TIMESTAMP | 0.5                   | 0.05          | 0                 | 0.9               | ETH        | 18                  |
    11      And the markets:
    12        | 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 | market type | sla params      | 
    13        | ETH/DEC19 | ETH        | USD   | default-simple-risk-model-4 | default-margin-calculator | 1                | default-none | default-none     | perp-oracle        | 0.25                   | 0                         | 0              | 0                       | perp        | default-futures |
    14      And time is updated to "2024-01-01T00:00:00Z"
    15      And the parties deposit on asset's general account the following amount:
    16        | party  | asset | amount     |
    17        | party1 | USD   | 1000000000 |
    18        | party2 | USD   | 1000000000 |
    19        | party3 | USD   | 1000000000 |
    20        | party4 | USD   | 1000000000 |
    21        | aux    | USD   | 1000000000 |
    22        | aux2   | USD   | 1000000000 |
    23  
    24      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    25      When the parties place the following orders:
    26        | party  | market id | side | volume | price   | resulting trades | type       | tif     |
    27        | aux    | ETH/DEC19 | buy  | 1      | 50      | 0                | TYPE_LIMIT | TIF_GTC |
    28        | aux2   | ETH/DEC19 | sell | 1      | 5000    | 0                | TYPE_LIMIT | TIF_GTC |
    29        | party1 | ETH/DEC19 | sell | 1      | 1590    | 0                | TYPE_LIMIT | TIF_GTC |
    30        | party2 | ETH/DEC19 | buy  | 1      | 1590    | 0                | TYPE_LIMIT | TIF_GTC |
    31      Then the opening auction period ends for market "ETH/DEC19"
    32      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    33  
    34      When the parties place the following orders:
    35        | party  | market id | side | volume | price   | resulting trades | type       | tif     |
    36        | party4 | ETH/DEC19 | buy  | 1      | 1590    | 0                | TYPE_LIMIT | TIF_GTC |
    37        | party3 | ETH/DEC19 | sell | 1      | 1590    | 1                | TYPE_LIMIT | TIF_GTC |
    38      And the parties submit update margin mode:
    39        | party  | market    | margin_mode     | margin_factor |
    40        | party3 | ETH/DEC19 | isolated margin | 0.5           |
    41        | party4 | ETH/DEC19 | isolated margin | 0.75          |
    42      Then the mark price should be "1590" for the market "ETH/DEC19"
    43      And the parties should have the following margin levels:
    44        | party  | market id | maintenance | margin mode     |
    45        | party1 | ETH/DEC19 | 556500      | cross margin    |
    46        | party2 | ETH/DEC19 | 556500      | cross margin    |
    47        | party3 | ETH/DEC19 | 556500      | isolated margin |
    48        | party4 | ETH/DEC19 | 556500      | isolated margin |
    49        
    50      When the oracles broadcast data with block time signed with "0xCAFECAFE1":
    51        | name             | value                  | time offset |
    52        | perp.ETH.value   | 1600000000000000000000 | 0s          |
    53      And time is updated to "2024-01-01T17:31:03Z"
    54      # We need a trade a different price to trigger MTM
    55      And the parties place the following orders:
    56        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    57        | aux    | ETH/DEC19 | buy  | 1      | 1591  | 0                | TYPE_LIMIT | TIF_GTC |
    58        | aux2   | ETH/DEC19 | sell | 1      | 1591  | 1                | TYPE_LIMIT | TIF_GTC |
    59      And the network moves ahead "5" blocks
    60      # Now trade at desired price and forward time again to trigger another MTM
    61      And the parties place the following orders:
    62        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    63        | aux    | ETH/DEC19 | buy  | 1      | 1590  | 0                | TYPE_LIMIT | TIF_GTC |
    64        | aux2   | ETH/DEC19 | sell | 1      | 1590  | 1                | TYPE_LIMIT | TIF_GTC |
    65      And the network moves ahead "5" blocks
    66      Then the parties should have the following margin levels:
    67        | party  | market id | maintenance | margin mode     |
    68        | party1 | ETH/DEC19 | 556500      | cross margin    |
    69        | party2 | ETH/DEC19 | 556580      | cross margin    |
    70        | party3 | ETH/DEC19 | 556500      | isolated margin |
    71        | party4 | ETH/DEC19 | 556580      | isolated margin |
    72  
    73      When the system unix time is "1704130273"
    74      And the oracles broadcast data with block time signed with "0xCAFECAFE1":
    75        | name             | value                  | time offset |
    76        | perp.funding.cue | 1704130273             | 0s          |
    77      Then the following funding period events should be emitted:
    78        | start               | end                  | internal twap | external twap | funding payment | funding rate |
    79        | 1704067201000000000 | 1704130273000000000  | 1590000       | 1600000       | 160             | 0.0001       |
    80      And the following transfers should happen:
    81        | from   | to     | from account            | to account              | market id | amount | asset | type                                  |
    82        | party2 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 160    | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS |
    83        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 160    | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN  |
    84        | party4 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 160    | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS |
    85        | market | party3 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 160    | USD   | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN  |