code.vegaprotocol.io/vega@v0.79.0/core/integration/features/rewards/average_notional_with_liquidation_reward.feature (about)

     1  Feature: Calculation of average position during closeout trades
     2  
     3      Background:
     4  
     5          # Initialise the network
     6          Given time is updated to "2023-01-01T00:00:00Z"
     7          And the average block duration is "1"
     8          And the following network parameters are set:
     9              | name                                    | value |
    10              | market.fee.factors.makerFee             | 0.001 |
    11              | network.markPriceUpdateMaximumFrequency | 0s    |
    12              | market.auction.minimumDuration          | 1     |
    13              | validators.epoch.length                 | 60s   |
    14              | limits.markets.maxPeggedOrders          | 4     |
    15              | referralProgram.minStakedVegaTokens     | 0     |
    16              | rewards.vesting.baseRate                | 1.0   |
    17  
    18  
    19          # Initialise the markets
    20          And the following assets are registered:
    21              | id       | decimal places | quantum |
    22              | USD-1-10 | 1              | 10      |
    23          And the markets:
    24              | id           | quote name | asset    | risk model                    | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      | decimal places | position decimal places |
    25              | ETH/USD-1-10 | ETH        | USD-1-10 | default-log-normal-risk-model | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 1e-3                   | 0                         | default-futures | 0              | 0                       |
    26  
    27          # Initialise the parties
    28          Given the parties deposit on asset's general account the following amount:
    29              | party                                                            | asset    | amount      |
    30              | lpprov                                                           | USD-1-10 | 10000000000 |
    31              | aux1                                                             | USD-1-10 | 10000000    |
    32              | aux2                                                             | USD-1-10 | 10000000    |
    33              | a3c024b4e23230c89884a54a813b1ecb4cb0f827a38641c66eeca466da6b2ddf | USD-1-10 | 10000000000 |
    34              | party1                                                           | USD-1-10 | 1000        |
    35  
    36          # Exit opening auctions
    37          Given the parties submit the following liquidity provision:
    38              | id  | party  | market id    | commitment amount | fee  | lp type    |
    39              | lp1 | lpprov | ETH/USD-1-10 | 1000000           | 0.01 | submission |
    40          And the parties place the following pegged iceberg orders:
    41              | party  | market id    | peak size | minimum visible size | side | pegged reference | volume | offset |
    42              | lpprov | ETH/USD-1-10 | 5000      | 1000                 | buy  | BID              | 10000  | 10     |
    43              | lpprov | ETH/USD-1-10 | 5000      | 1000                 | sell | ASK              | 10000  | 10     |
    44          When the parties place the following orders:
    45              | party | market id    | side | volume | price | resulting trades | type       | tif     |
    46              | aux1  | ETH/USD-1-10 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
    47              | aux1  | ETH/USD-1-10 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    48              | aux2  | ETH/USD-1-10 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    49              | aux2  | ETH/USD-1-10 | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
    50          And the opening auction period ends for market "ETH/USD-1-10"
    51          When the network moves ahead "1" blocks
    52          And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/USD-1-10"
    53  
    54      @Liquidation
    55      Scenario: Bug time-weighted average position not updated correctly during closeout trades
    56          # Setup such that distributed rewards are all vested the following epoch, i,e. the balance in the vested account is equal to the rewards distributed that epocha
    57  
    58          # Close open positions to simplify test
    59          When the parties place the following orders:
    60              | party | market id    | side | volume | price | resulting trades | type       | tif     |
    61              | aux2  | ETH/USD-1-10 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    62              | aux1  | ETH/USD-1-10 | sell | 1      | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
    63          Then the network moves ahead "1" epochs
    64  
    65          Given the parties submit the following recurring transfers:
    66              | id | from                                                             | from_account_type    | to                                                               | to_account_type                      | asset    | amount | start_epoch | end_epoch | factor | metric                           | metric_asset | markets | lock_period | window_length | distribution_strategy | entity_scope | individual_scope | staking_requirement | notional_requirement | ranks        |
    67              | 1  | a3c024b4e23230c89884a54a813b1ecb4cb0f827a38641c66eeca466da6b2ddf | ACCOUNT_TYPE_GENERAL | 0000000000000000000000000000000000000000000000000000000000000000 | ACCOUNT_TYPE_REWARD_AVERAGE_NOTIONAL | USD-1-10 | 10000  | 2           |           | 1      | DISPATCH_METRIC_AVERAGE_NOTIONAL | USD-1-10     |         | 1           | 1             | RANK                  | INDIVIDUALS  | ALL              | 0                   | 0                    | 1:10,2:5,4:1 |
    68          When the parties place the following orders:
    69              | party  | market id    | side | volume | price | resulting trades | type       | tif     |
    70              | aux1   | ETH/USD-1-10 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    71              | party1 | ETH/USD-1-10 | sell | 1      | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
    72          Then the network moves ahead "1" epochs
    73          Then parties should have the following vesting account balances:
    74              | party  | asset    | balance |
    75              | party1 | USD-1-10 | 5000    |
    76  
    77          # Move into the epoch then move the mark price triggering a closeout
    78          Given the network moves ahead "5" blocks
    79          And the parties place the following orders:
    80              | party | market id    | side | volume | price | resulting trades | type       | tif     |
    81              | aux2  | ETH/USD-1-10 | buy  | 1      | 1099  | 0                | TYPE_LIMIT | TIF_GTC |
    82              | aux1  | ETH/USD-1-10 | sell | 1      | 1099  | 1                | TYPE_LIMIT | TIF_GTC |
    83          When the network moves ahead "2" blocks
    84          # Trades should result in all parties having no open position
    85          Then the following trades should be executed:
    86              | buyer   | price | size | seller  | aggressor side |
    87              | party1  | 1099  | 1    | network | sell           |
    88              | network | 1100  | 1    | aux2    | buy            |
    89          And the parties should have the following profit and loss:
    90              | party  | volume | unrealised pnl | realised pnl |
    91              | party1 | 0      | 0              | -890         |
    92              | aux1   | 0      | 0              | 890          |
    93              | aux2   | 0      | 0              | 0            |
    94              | lpprov | 0      | 0              | 0            |
    95          # Expect to see rewards as positions open at the start of the epoch
    96          Then parties should have the following vesting account balances:
    97              | party  | asset    | balance |
    98              | party1 | USD-1-10 | 5000    |
    99              | aux1   | USD-1-10 | 5000    |
   100          Given the network moves ahead "1" epochs
   101          # At the beginning of the epoch the party had some position so they still get some reward at this epoch
   102          Then parties should have the following vesting account balances:
   103              | party  | asset    | balance |
   104              | party1 | USD-1-10 | 3846    |
   105              | aux1   | USD-1-10 | 3846    |
   106              | aux2   | USD-1-10 | 1923    |
   107  
   108          Given the network moves ahead "1" epochs
   109          # there are still rewards because while the position is 0 at the beginning of the epoch, the timeweighted position will only become 0
   110          # at the beginning of the next epoch
   111          Then parties should have the following vesting account balances:
   112              | party  | asset    | balance |
   113              | party1 | USD-1-10 | 3333    |
   114              | aux2   | USD-1-10 | 3333    |
   115              | aux1   | USD-1-10 | 3333    |
   116  
   117          Given the network moves ahead "1" epochs
   118          # Expect to see no rewards as no positions open at the start of the epoch
   119          Then parties should have the following vesting account balances:
   120              | party  | asset    | balance |
   121              | party1 | USD-1-10 | 0       |
   122              | aux2   | USD-1-10 | 0       |
   123              | aux1   | USD-1-10 | 0       |
   124  
   125