code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0029-FEES-fees.feature (about)

     1  Feature: Fees calculations
     2  
     3    Background:
     4      Given the fees configuration named "fees-config-1":
     5        | maker fee | infrastructure fee |
     6        | 0.004     | 0.003              |
     7      And the price monitoring named "price-monitoring":
     8        | horizon | probability | auction extension |
     9        | 60      | 0.99        | 2                 |
    10      And the simple risk model named "simple-risk-model-1":
    11        | long | short | max move up | min move down | probability of trading |
    12        | 0.2  | 0.1   | 100         | -100          | 0.1                    |
    13  
    14      And the following network parameters are set:
    15        | name                                    | value |
    16        | network.markPriceUpdateMaximumFrequency | 0s    |
    17        | limits.markets.maxPeggedOrders          | 2     |
    18        | market.fee.factors.buybackFee           | 0.001 |
    19        | market.fee.factors.treasuryFee          | 0.002 |
    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 | sla params      |
    23        | ETH/DEC21 | ETH/USD    | USD   | simple-risk-model-1 | default-margin-calculator | 2                | fees-config-1 | price-monitoring | default-eth-for-future | 0.25                   | 0                         | default-futures |
    24  
    25      And the average block duration is "2"
    26    Scenario: 001: Testing fees get collected when amended order trades (0029-FEES-005)
    27      Given the parties deposit on asset's general account the following amount:
    28        | party   | asset | amount |
    29        | aux1    | USD   | 100000 |
    30        | aux2    | USD   | 100000 |
    31        | aux3    | USD   | 100000 |
    32        | aux4    | USD   | 100000 |
    33        | trader1 | USD   | 10000  |
    34        | trader2 | USD   | 10000  |
    35        | trader3 | USD   | 490    |
    36        | trader4 | USD   | 250    |
    37        | trader5 | USD   | 5000   |
    38        | trader6 | USD   | 5000   |
    39  
    40      When the parties submit the following liquidity provision:
    41        | id  | party | market id | commitment amount | fee   | lp type    |
    42        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.002 | submission |
    43        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.002 | submission |
    44      When the network moves ahead "2" blocks
    45  
    46      And the parties place the following orders:
    47        | party | market id | side | volume | price | resulting trades | type       | tif     |
    48        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    49        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    50        | aux3  | ETH/DEC21 | buy  | 1      | 820   | 0                | TYPE_LIMIT | TIF_GTC |
    51        | aux4  | ETH/DEC21 | sell | 1      | 1180  | 0                | TYPE_LIMIT | TIF_GTC |
    52      Then the opening auction period ends for market "ETH/DEC21"
    53      And the market data for the market "ETH/DEC21" should be:
    54        | mark price | trading mode            |
    55        | 1000       | TRADING_MODE_CONTINUOUS |
    56  
    57      And the following trades should be executed:
    58        | buyer | price | size | seller |
    59        | aux1  | 1000  | 1    | aux2   |
    60      Then the parties should have the following account balances:
    61        | party | asset | market id | margin | general |
    62        | aux1  | USD   | ETH/DEC21 | 540    | 89460   |
    63      #0029-FEES-036:no fees are collected during opening auction
    64  
    65      And the order book should have the following volumes for market "ETH/DEC21":
    66        | side | price | volume |
    67        | buy  | 820   | 1      |
    68        | sell | 1180  | 1      |
    69  
    70      When the parties place the following orders:
    71        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
    72        | trader1 | ETH/DEC21 | buy  | 2      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | t1-b2-01  |
    73        | trader2 | ETH/DEC21 | sell | 2      | 1004  | 0                | TYPE_LIMIT | TIF_GTC | t2-s4-01  |
    74  
    75      Then the market data for the market "ETH/DEC21" should be:
    76        | mark price | trading mode            |
    77        | 1000       | TRADING_MODE_CONTINUOUS |
    78  
    79      Then the parties should have the following account balances:
    80        | party   | asset | market id | margin | general |
    81        | trader1 | USD   | ETH/DEC21 | 480    | 9520    |
    82        | trader2 | USD   | ETH/DEC21 | 240    | 9760    |
    83  
    84      And the parties amend the following orders:
    85        | party   | reference | price | size delta | tif     |
    86        | trader2 | t2-s4-01  | 1002  | 0          | TIF_GTC |
    87  
    88      Then the market data for the market "ETH/DEC21" should be:
    89        | mark price | last traded price | trading mode            |
    90        | 1000       | 1002              | TRADING_MODE_CONTINUOUS |
    91      And the following trades should be executed:
    92        | buyer   | price | size | seller  |
    93        | trader1 | 1002  | 2    | trader2 |
    94  
    95      # For trader1-
    96      # trade_value_for_fee_purposes for trader1 = size_of_trade * price_of_trade = 2 * 1002 = 2004
    97      # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.003 * 2004 = 6.012 = 7 (rounded up to nearest whole value)
    98      # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.004 * 2004 = 8.016 = 9 (rounded up to nearest whole value)
    99      # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 (rounded up to nearest whole value)
   100      # buy_back_fee = buy_back_factor * trade_value_for_fee_purposes = 0.001 * 2004 = 2.004 = 3
   101      # treasury_fee = treasury_fee_factor * trade
   102      #_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5
   103  
   104      And the following transfers should happen:
   105        | from    | to      | from account            | to account                       | market id | amount | asset |
   106        #0029-FEES-046:Once total fee is collected, `maker_fee = fee_factor[maker]  * trade_value_for_fee_purposes` is transferred to maker at the end of fee distribution time.
   107        | trader2 | market  | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 9      | USD   |
   108        #0029-FEES-045:Once total fee is collected, `infrastructure_fee = fee_factor[infrastucture]  * trade_value_for_fee_purposes` is transferred to infrastructure fee pool for that asset at the end of fee distribution time.
   109        | trader2 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 7      | USD   |
   110        #0029-FEES-048:Once total fee is collected, `liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes` (with appropriate fraction of `high_volume_maker_fee` deducted) is transferred to the treasury fee pool for that asset
   111        | trader2 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 5      | USD   |
   112        #0029-FEES-049:Once total fee is collected, `treasury_fee = fee_factor[treasury] * trade_value_for_fee_purposes` (with appropriate fraction of `high_volume_maker_fee` deducted) is transferred to the treasury fee pool for that asset
   113        | trader2 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_NETWORK_TREASURY    |           | 5      | USD   |
   114        #0029-FEES-050:Once total fee is collected, `buyback_fee = fee_factor[buyback] * trade_value_for_fee_purposes` (with with appropriate fraction of `high_volume_maker_fee` deducted) is transferred to the buyback fee pool for that asset
   115        | trader2 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_BUY_BACK_FEES       |           | 3      | USD   |
   116        | market  | trader1 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 9      | USD   |
   117  
   118      # total_fee = maker_fee + infrastructure_fee + liquidity_fee + buy back + treasury =  9 + 7 + 5 + 8 = 29
   119      #0029-FEES-038: In a matched trade, if the price taker has enough asset to cover the total fee in their general account, then the total fee should be taken from their general account.
   120      Then the parties should have the following account balances:
   121        | party   | asset | market id | margin | general |
   122        | trader1 | USD   | ETH/DEC21 | 480    | 9529    |
   123        | trader2 | USD   | ETH/DEC21 | 240    | 9731    |
   124  
   125      When the parties place the following orders:
   126        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   127        | trader3 | ETH/DEC21 | buy  | 2      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | t1-b2-01  |
   128        | trader4 | ETH/DEC21 | sell | 2      | 1002  | 1                | TYPE_LIMIT | TIF_GTC | t2-s4-01  |
   129  
   130      #trader4 started with asset of 250, and paid 29 for total trading fee
   131      #0029-FEES-039:In a matched trade, if the price taker has insufficient asset to cover the total fee in their general account (but has enough in general + margin account), then the remainder will be taken from their margin account.
   132      Then the parties should have the following account balances:
   133        | party   | asset | market id | margin | general |
   134        | trader3 | USD   | ETH/DEC21 | 480    | 19      |
   135        | trader4 | USD   | ETH/DEC21 | 221    | 0       |
   136  
   137      And the following transfers should happen:
   138        | from    | to      | from account            | to account                       | market id | amount | asset |
   139        | market  | trader3 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 9      | USD   |
   140        | trader4 | market  | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 9      | USD   |
   141        | trader4 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_BUY_BACK_FEES       |           | 1      | USD   |
   142        | trader4 |         | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 7      | USD   |
   143        | trader4 |         | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 5      | USD   |
   144        | trader4 |         | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_NETWORK_TREASURY    | ETH/DEC21 | 5      | USD   |
   145  
   146      And the market data for the market "ETH/DEC21" should be:
   147        | mark price | trading mode            | horizon | min bound | max bound |
   148        | 1000       | TRADING_MODE_CONTINUOUS | 60      | 900       | 1100      |
   149  
   150      When the parties place the following orders:
   151        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   152        | trader5 | ETH/DEC21 | buy  | 2      | 1101  | 0                | TYPE_LIMIT | TIF_GTC | t1-b2-01  |
   153        | trader6 | ETH/DEC21 | sell | 2      | 1101  | 0                | TYPE_LIMIT | TIF_GTC | t2-s4-01  |
   154  
   155      And the market data for the market "ETH/DEC21" should be:
   156        | mark price | trading mode                    | horizon | min bound | max bound |
   157        | 1000       | TRADING_MODE_MONITORING_AUCTION | 60      | 900       | 1100      |
   158  
   159      When the network moves ahead "4" blocks
   160  
   161      And the market data for the market "ETH/DEC21" should be:
   162        | mark price | trading mode            | horizon | min bound | max bound |
   163        | 1101       | TRADING_MODE_CONTINUOUS | 60      | 1002      | 1200      |
   164  
   165      # trade_value_for_fee_purposes for trader1 = size_of_trade * price_of_trade = 2 * 1101 = 2202
   166      # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.003 * 2202 = 6.606 = 7 (rounded up to nearest whole value)
   167      # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.004 * 2202 = 8.808 = 9 (rounded up to nearest whole value)
   168      # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.002 * 2202 = 4.404 = 5 (rounded up to nearest whole value)
   169      # buy_back_fee = buy_back_factor * trade_value_for_fee_purposes = 0.001 * 2202 = 2.202 = 3
   170      # treasury_fee = treasury_fee_factor * trade
   171      #_value_for_fee_purposes = 0.002 * 2202 = 4.404 = 5
   172  
   173      And the following transfers should happen:
   174        | from    | to | from account         | to account                       | market id | amount | asset |
   175        #0029-FEES-037:During normal auction (including market protection), each side in a matched trade should contribute `0.5*(infrastructure_fee + liquidity_fee + treasury_fee + buyback_fee)`
   176        | trader5 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 4      | USD   |
   177        | trader6 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 4      | USD   |
   178        | trader5 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 3      | USD   |
   179        | trader6 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 3      | USD   |
   180        | trader5 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_NETWORK_TREASURY    | ETH/DEC21 | 3      | USD   |
   181        | trader6 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_NETWORK_TREASURY    | ETH/DEC21 | 3      | USD   |
   182        | trader5 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES       |           | 2      | USD   |
   183        | trader6 |    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES       |           | 2      | USD   |
   184