code.vegaprotocol.io/vega@v0.79.0/core/integration/features/spot/liquidity_provision/0042-LIQF-spots.feature (about)

     1  Feature: Test liquidity provider reward distribution; Should also cover liquidity-fee-setting and equity-like-share calc and total stake.
     2    # to look into and test: If an equity-like share is small and LP rewards are distributed immediately, then how do we round? (does a small share get rounded up or down, do they all add up?)
     3    #Check what happens with time and distribution period (both in genesis and mid-market)
     4  
     5    Background:
     6  
     7      Given the simple risk model named "simple-risk-model-1":
     8        | long | short | max move up | min move down | probability of trading |
     9        | 0.1  | 0.1   | 500         | 500           | 0.1                    |
    10      And the price monitoring named "price-monitoring":
    11        | horizon | probability | auction extension |
    12        | 1       | 0.99        | 3                 |
    13      And the fees configuration named "fees-config-1":
    14        | maker fee | infrastructure fee | liquidity fee method | liquidity fee constant |
    15        | 0.0004    | 0.001              | METHOD_CONSTANT      | 0.08                   |
    16      And the fees configuration named "fees-config-2":
    17        | maker fee | infrastructure fee | liquidity fee method | liquidity fee constant |
    18        | 0.0004    | 0.001              | METHOD_CONSTANT      | 0.01                   |
    19      And the fees configuration named "fees-config-3":
    20        | maker fee | infrastructure fee | liquidity fee method    | liquidity fee constant |
    21        | 0.0004    | 0.001              | METHOD_WEIGHTED_AVERAGE | 0.01                   |
    22      And the fees configuration named "fees-config-4":
    23        | maker fee | infrastructure fee | liquidity fee method | liquidity fee constant |
    24        | 0.0004    | 0.001              | METHOD_MARGINAL_COST | 0.01                   |
    25  
    26  
    27      Given the following assets are registered:
    28        | id  | decimal places |
    29        | ETH | 1              |
    30        | BTC | 1              |
    31      And the following network parameters are set:
    32        | name                                                | value |
    33        | market.value.windowLength                           | 1h    |
    34        | network.markPriceUpdateMaximumFrequency             | 0s    |
    35        | limits.markets.maxPeggedOrders                      | 8     |
    36        | validators.epoch.length                             | 5s    |
    37        | market.liquidity.providersFeeCalculationTimeStep    | 5s    |
    38  
    39      Given the liquidity monitoring parameters:
    40        | name               | triggering ratio | time window | scaling factor |
    41        | lqm-params         | 0.0              | 10s          | 0.75           |
    42      
    43      And the liquidity sla params named "SLA":
    44        | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    45        | 1.0         | 0.5                          | 1                             | 1.0                    |
    46  
    47      And the spot markets:
    48        | id      | name    | base asset | quote asset | risk model          | auction duration | fees          | price monitoring | sla params | liquidity monitoring |
    49        | BTC/ETH | BTC/ETH | BTC        | ETH         | simple-risk-model-1 | 2                | fees-config-4 | price-monitoring | SLA        | lqm-params           |
    50  
    51      Given the average block duration is "1"
    52  
    53    Scenario: 001: The resulting liquidity-fee-factor is always equal to one of the liquidity provider's individually nominated fee factors  (0042-LIQF-063)
    54  
    55      Given the parties deposit on asset's general account the following amount:
    56        | party  | asset | amount     |
    57        | lp1    | BTC   | 1000000000 |
    58        | lp2    | BTC   | 1000000000 |
    59        | party1 | BTC   | 100000000  |
    60        | party2 | BTC   | 100000000  |
    61        | lp1    | ETH   | 1000000000 |
    62        | lp2    | ETH   | 1000000000 |
    63        | party1 | ETH   | 100000000  |
    64        | party2 | BTC   | 100000000  |
    65  
    66      And the parties submit the following liquidity provision:
    67        | id  | party | market id | commitment amount | fee   | lp type    |
    68        | lp1 | lp1   | BTC/ETH   | 5000              | 0.001 | submission |
    69      And the parties place the following pegged iceberg orders:
    70        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    71        | lp1   | BTC/ETH | 4         | 1                    | buy  | MID              | 4          | 1      |
    72        | lp1   | BTC/ETH | 4         | 1                    | sell | MID              | 4          | 1      |
    73      And the parties submit the following liquidity provision:
    74        | id  | party | market id | commitment amount | fee   | lp type    |
    75        | lp2 | lp2   | BTC/ETH   | 5000              | 0.002 | submission |
    76      And the parties place the following pegged iceberg orders:
    77        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    78        | lp2   | BTC/ETH | 4         | 1                    | buy  | MID              | 4          | 1      |
    79        | lp2   | BTC/ETH | 4         | 1                    | sell | MID              | 4          | 1      |
    80  
    81      Then the parties place the following orders:
    82        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    83        | party1 | BTC/ETH   | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
    84        | party1 | BTC/ETH   | buy  | 90     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    85        | party2 | BTC/ETH   | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
    86        | party2 | BTC/ETH   | sell | 90     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    87  
    88      Then the opening auction period ends for market "BTC/ETH"
    89  
    90      When the network moves ahead "1" blocks
    91  
    92      And the following trades should be executed:
    93        | buyer  | price | size | seller |
    94        | party1 | 1000  | 90   | party2 |
    95  
    96      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "BTC/ETH"
    97      And the mark price should be "1000" for the market "BTC/ETH"
    98      And the supplied stake should be "10000" for the market "BTC/ETH"
    99  
   100      # 10,000 staked and scaling factor is 10
   101      And the target stake should be "7500" for the market "BTC/ETH"
   102  
   103      And the liquidity provider fee shares for the market "BTC/ETH" should be:
   104        | party | equity like share | average entry valuation |
   105        | lp1   | 0.5               | 5000                    |
   106        | lp2   | 0.5               | 10000                   |
   107  
   108  
   109      And the liquidity fee factor should be "0.002" for the market "BTC/ETH"
   110  
   111      # no fees in auction
   112      And the accumulated liquidity fees should be "0" for the market "BTC/ETH"
   113  
   114      Then the parties place the following orders with ticks:
   115        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference   |
   116        | party1 | BTC/ETH   | sell | 20     | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party1-sell |
   117        | party2 | BTC/ETH   | buy  | 20     | 1000  | 3                | TYPE_LIMIT | TIF_GTC | party2-buy  |
   118  
   119      And the following trades should be executed:
   120        | buyer  | price | size | seller |
   121        | party2 | 951   | 4    | lp1    |
   122        | party2 | 951   | 4    | lp2    |
   123        | party2 | 1000  | 12   | party1 |
   124  
   125      And the accumulated liquidity fees should be "394" for the market "BTC/ETH"
   126  
   127      # opening auction + time window
   128      Then time is updated to "2019-11-30T00:10:05Z"
   129  
   130      Then the following transfers should happen:
   131        | from   | to  | from account                | to account                     | market id | amount | asset |
   132        | market | lp1 | ACCOUNT_TYPE_FEES_LIQUIDITY | ACCOUNT_TYPE_LP_LIQUIDITY_FEES | BTC/ETH   | 197    | ETH   |
   133        | market | lp2 | ACCOUNT_TYPE_FEES_LIQUIDITY | ACCOUNT_TYPE_LP_LIQUIDITY_FEES | BTC/ETH   | 197    | ETH   |
   134     
   135    Scenario: 002: Liquidity fee factors are recalculated every time the liquidity demand estimate changes.  (0042-LIQF-064)
   136  
   137      Given the parties deposit on asset's general account the following amount:
   138        | party  | asset | amount     |
   139        | lp1    | BTC   | 1000000000 |
   140        | lp2    | BTC   | 1000000000 |
   141        | party1 | BTC   | 100000000  |
   142        | party2 | BTC   | 100000000  |
   143        | lp1    | ETH   | 1000000000 |
   144        | lp2    | ETH   | 1000000000 |
   145        | party1 | ETH   | 100000000  |
   146        | party2 | BTC   | 100000000  |
   147  
   148      And the parties submit the following liquidity provision:
   149        | id  | party | market id | commitment amount | fee   | lp type    |
   150        | lp1 | lp1   | BTC/ETH   | 5000              | 0.001 | submission |
   151      And the parties place the following pegged iceberg orders:
   152        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   153        | lp1   | BTC/ETH | 4         | 1                    | buy  | MID              | 4          | 1      |
   154        | lp1   | BTC/ETH | 4         | 1                    | sell | MID              | 4          | 1      |
   155  
   156      Then the parties place the following orders:
   157        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   158        | party1 | BTC/ETH   | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   159        | party1 | BTC/ETH   | buy  | 90     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   160        | party2 | BTC/ETH   | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
   161        | party2 | BTC/ETH   | sell | 90     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   162  
   163      Then the opening auction period ends for market "BTC/ETH"
   164  
   165      When the network moves ahead "1" blocks
   166  
   167      And the following trades should be executed:
   168        | buyer  | price | size | seller |
   169        | party1 | 1000  | 90   | party2 |
   170  
   171      And the liquidity fee factor should be "0.001" for the market "BTC/ETH"
   172  
   173     
   174      # now another LP enters with a different fee
   175      And the parties submit the following liquidity provision:
   176        | id  | party | market id | commitment amount | fee   | lp type    |
   177        | lp2 | lp2   | BTC/ETH   | 5000              | 0.002 | submission |
   178      And the parties place the following pegged iceberg orders:
   179        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   180        | lp2   | BTC/ETH   | 4         | 1                    | buy  | MID              | 4          | 1      |
   181        | lp2   | BTC/ETH   | 4         | 1                    | sell | MID              | 4          | 1      |
   182  
   183      # no liqudiity fee change
   184      When the network moves ahead "1" blocks
   185      And the liquidity fee factor should be "0.001" for the market "BTC/ETH"
   186  
   187      # until we eneter a new epoch and the LP provisions become active
   188      When the network moves ahead "1" epochs
   189      And the liquidity fee factor should be "0.002" for the market "BTC/ETH"
   190  
   191  
   192    Scenario: 003: If passage of time causes the liquidity demand estimate to change, the fee factor is correctly recalculated.  (0042-LIQF-065)
   193  
   194      Given the parties deposit on asset's general account the following amount:
   195        | party  | asset | amount     |
   196        | lp1    | BTC   | 1000000000 |
   197        | lp2    | BTC   | 1000000000 |
   198        | lp3    | BTC   | 1000000000 |
   199        | party1 | BTC   | 100000000  |
   200        | party2 | BTC   | 100000000  |
   201        | lp1    | ETH   | 1000000000 |
   202        | lp2    | ETH   | 1000000000 |
   203        | lp3    | ETH   | 1000000000 |
   204        | party1 | ETH   | 100000000  |
   205        | party2 | BTC   | 100000000  |
   206  
   207      And the parties submit the following liquidity provision:
   208        | id  | party | market id | commitment amount | fee   | lp type    |
   209        | lp1 | lp1   | BTC/ETH   | 10000             | 0.001 | submission |
   210      And the parties place the following pegged iceberg orders:
   211        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   212        | lp1   | BTC/ETH | 4         | 1                    | buy  | MID              | 4          | 1      |
   213        | lp1   | BTC/ETH | 4         | 1                    | sell | MID              | 4          | 1      |
   214  
   215      # now another LP enters with a different fee but small commitment
   216      And the parties submit the following liquidity provision:
   217        | id  | party | market id | commitment amount | fee   | lp type    |
   218        | lp2 | lp2   | BTC/ETH   | 1000              | 0.002 | submission |
   219      And the parties place the following pegged iceberg orders:
   220        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   221        | lp2   | BTC/ETH   | 4         | 1                    | buy  | MID              | 4          | 1      |
   222        | lp2   | BTC/ETH   | 4         | 1                    | sell | MID              | 4          | 1      |
   223  
   224       # now another LP enters with a big fee
   225      And the parties submit the following liquidity provision:
   226        | id  | party | market id | commitment amount | fee   | lp type    |
   227        | lp3 | lp3   | BTC/ETH   | 3000              | 0.003 | submission |
   228      And the parties place the following pegged iceberg orders:
   229        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   230        | lp3   | BTC/ETH   | 4         | 1                    | buy  | MID              | 4          | 1      |
   231        | lp3   | BTC/ETH   | 4         | 1                    | sell | MID              | 4          | 1      |
   232  
   233      Then the parties place the following orders:
   234        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   235        | party1 | BTC/ETH   | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   236        | party1 | BTC/ETH   | buy  | 90     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   237        | party2 | BTC/ETH   | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
   238        | party2 | BTC/ETH   | sell | 90     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   239  
   240      Then the opening auction period ends for market "BTC/ETH"
   241  
   242      When the network moves ahead "1" blocks
   243  
   244      And the following trades should be executed:
   245        | buyer  | price | size | seller |
   246        | party1 | 1000  | 90   | party2 |
   247  
   248      Then the liquidity fee factor should be "0.002" for the market "BTC/ETH"
   249  
   250      # LP3 now cancels
   251      And the parties submit the following liquidity provision:
   252        | id  | party | market id | commitment amount | fee   | lp type      |
   253        | lp3 | lp3   | BTC/ETH   | 3000              | 0.003 | cancellation |
   254  
   255      When the network moves ahead "1" epochs
   256      Then the liquidity fee factor should be "0.002" for the market "BTC/ETH"
   257  
   258      # the time window is 10s so from cancellation the target stake (and the calculated fee) should only drop after 10s
   259      When the network moves ahead "9" blocks
   260      Then the liquidity fee factor should be "0.002" for the market "BTC/ETH"
   261  
   262      When the network moves ahead "1" blocks
   263      Then the liquidity fee factor should be "0.001" for the market "BTC/ETH"
   264  
   265    Scenario: 004 Liquidity fee setting to METHOD_CONSTANT(0042-LIQF-070), METHOD_MARGINAL_COST (0042-LIQF-071), and METHOD_WEIGHTED_AVERAGE(0042-LIQF-069)
   266      # setup accounts
   267      Given the parties deposit on asset's general account the following amount:
   268        | party  | asset | amount     |
   269        | lp1    | BTC   | 1000000000 |
   270        | lp2    | BTC   | 1000000000 |
   271        | party1 | BTC   | 100000000  |
   272        | party2 | BTC   | 100000000  |
   273        | lp1    | ETH   | 1000000000 |
   274        | lp2    | ETH   | 1000000000 |
   275        | party1 | ETH   | 100000000 |
   276        | party2 | ETH   | 100000000  |
   277  
   278      And the parties submit the following liquidity provision:
   279        | id  | party | market id | commitment amount | fee   | lp type    |
   280        | lp1 | lp1   | BTC/ETH | 800               | 0.005 | submission |
   281        | lp2 | lp2   | BTC/ETH | 300               | 0.004 | submission |
   282  
   283      And the parties place the following pegged iceberg orders:
   284        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   285        | lp1   | BTC/ETH | 12        | 1                    | buy  | BID              | 12     | 2      |
   286        | lp1   | BTC/ETH | 12        | 1                    | buy  | MID              | 12     | 1      |
   287        | lp1   | BTC/ETH | 12        | 1                    | sell | ASK              | 12     | 2      |
   288        | lp1   | BTC/ETH | 12        | 1                    | sell | MID              | 12     | 1      |
   289  
   290      When the parties place the following orders:
   291        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   292        | party1 | BTC/ETH | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   293        | party1 | BTC/ETH | buy  | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   294        | party2 | BTC/ETH | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
   295        | party2 | BTC/ETH | sell | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   296  
   297      Then the opening auction period ends for market "BTC/ETH"
   298  
   299      # update to method constant value 0.08 (0042-LIQF-070)
   300      When the spot markets are updated:
   301        | id        | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
   302        | BTC/ETH   | lqm-params             | 1e-3                   | 0                       | fees-config-1          |
   303  
   304      When the network moves ahead "1" blocks
   305  
   306      And the following trades should be executed:
   307        | buyer  | price | size | seller |
   308        | party1 | 1000  | 10   | party2 |
   309  
   310      And the market data for the market "BTC/ETH" should be:
   311        | mark price | trading mode            | min bound | max bound | target stake | supplied stake |
   312        | 1000       | TRADING_MODE_CONTINUOUS | 500       | 1500      | 825          | 1100           |
   313  
   314      And the liquidity fee factor should be "0.08" for the market "BTC/ETH"
   315  
   316  
   317      # update to constant 0.01
   318      When the spot markets are updated:
   319        | id        | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
   320        | BTC/ETH | lqm-params             | 1e-3                   | 0                         | fees-config-2          |
   321      Then the network moves ahead "2" blocks
   322      And the liquidity fee factor should be "0.01" for the market "BTC/ETH"
   323  
   324      # update to weighted average (0042-LIQF-069)
   325      When the spot markets are updated:
   326        | id        | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
   327        | BTC/ETH | lqm-params           | 1e-3                   | 0                         | fees-config-3          |
   328      Then the network moves ahead "1" blocks
   329      And the liquidity fee factor should be "0.0047272727272727" for the market "BTC/ETH"
   330  
   331      When the parties submit the following liquidity provision:
   332        | id  | party | market id | commitment amount | fee   | lp type   |
   333        | lp1 | lp1   | BTC/ETH | 800               | 0.006 | amendment |
   334      Then the network moves ahead "1" blocks
   335      And the liquidity fee factor should be "0.0054545454545455" for the market "BTC/ETH"
   336  
   337      # update to marginal cost (0042-LIQF-071)
   338      When the spot markets are updated:
   339        | id        | liquidity monitoring | linear slippage factor | quadratic slippage factor | liquidity fee settings |
   340        | BTC/ETH | lqm-params           | 1e-3                   | 0                         | fees-config-4          |
   341  
   342      When the parties submit the following liquidity provision:
   343        | id  | party | market id | commitment amount | fee    | lp type   |
   344        | lp1 | lp1   | BTC/ETH | 800               | 0.0375 | amendment |
   345      Then the network moves ahead "1" blocks
   346      And the liquidity fee factor should be "0.0375" for the market "BTC/ETH"