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

     1  Feature: Discounts from multiple sources
     2  
     3    Background:
     4  
     5      # Initialise timings
     6      Given time is updated to "2023-01-01T00:00:00Z"
     7      And the average block duration is "1"
     8      And the margin calculator named "margin-calculator-1":
     9        | search factor | initial factor | release factor |
    10        | 1.2           | 1.5            | 1.7            |
    11      And the log normal risk model named "log-normal-risk-model":
    12        | risk aversion | tau | mu | r | sigma |
    13        | 0.000001      | 0.1 | 0  | 0 | 1.0   |
    14      And the price monitoring named "price-monitoring":
    15        | horizon | probability | auction extension |
    16        | 3600    | 0.99        | 15                |
    17  
    18      # Initialise the markets and network parameters
    19      Given the following network parameters are set:
    20        | name                                                    | value      |
    21        | market.fee.factors.infrastructureFee                    | 0.01       |
    22        | market.fee.factors.makerFee                             | 0.01       |
    23        | market.auction.minimumDuration                          | 1          |
    24        | limits.markets.maxPeggedOrders                          | 4          |
    25        | referralProgram.minStakedVegaTokens                     | 0          |
    26        | referralProgram.maxPartyNotionalVolumeByQuantumPerEpoch | 1000000000 |
    27        | referralProgram.maxReferralRewardProportion             | 0.1        |
    28        | validators.epoch.length                                 | 10s        |
    29  
    30  
    31      # Initalise the referral program
    32      Given the referral benefit tiers "rbt":
    33        | minimum running notional taker volume | minimum epochs | referral reward infra factor | referral reward maker factor | referral reward liquidity factor | referral discount infra factor | referral discount maker factor | referral discount liquidity factor |
    34        | 1000                                  | 2              | 0.0                          | 0.0                          | 0.0                              | 0.11                           | 0.12                           | 0.13                               |
    35        | 10000                                 | 2              | 0.0                          | 0.0                          | 0.0                              | 1.0                            | 1.0                            | 1.0                                |
    36  
    37      And the referral staking tiers "rst":
    38        | minimum staked tokens | referral reward multiplier |
    39        | 1                     | 1                          |
    40      And the referral program:
    41        | end of program       | window length | benefit tiers | staking tiers |
    42        | 2023-12-12T12:12:12Z | 7             | rbt           | rst           |
    43      # Initialise the volume discount program
    44      And the volume discount program tiers named "vdt":
    45        | volume | infra factor | liquidity factor | maker factor |
    46        | 1000   | 0.11         | 0.12             | 0.13         |
    47        | 1000   | 0.11         | 0.12             | 0.13         |
    48  
    49      And the volume discount program:
    50        | id  | tiers | closing timestamp | window length |
    51        | id1 | vdt   | 0                 | 7             |
    52      # Move to the next epoch to start the programs
    53      And the network moves ahead "1" epochs
    54  
    55  
    56      # Initialse the assets and markets
    57      And the following assets are registered:
    58        | id      | decimal places | quantum |
    59        | USD.1.1 | 1              | 1       |
    60      And the markets:
    61        | 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 |
    62        | ETH/USD.1.1 | ETH        | USD.1.1 | default-log-normal-risk-model | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 1e-3                   | 0                         | default-futures | 1              | 1                       |
    63        | ETH/USD.1.2 | ETH        | USD.1.1 | log-normal-risk-model         | margin-calculator-1       | 1                | default-none | price-monitoring | default-eth-for-future | 1e-3                   | 0                         | default-futures | 1              | 1                       |
    64      And the liquidity monitoring parameters:
    65        | name       | triggering ratio | time window | scaling factor |
    66        | lqm-params | 1.0              | 3600s       | 1              |
    67      When the markets are updated:
    68        | id          | liquidity monitoring | linear slippage factor | quadratic slippage factor |
    69        | ETH/USD.1.1 | lqm-params           | 1e-3                   | 0                         |
    70        | ETH/USD.1.2 | lqm-params           | 1e-3                   | 0                         |
    71  
    72      # Initialise the parties
    73      Given the parties deposit on asset's general account the following amount:
    74        | party     | asset   | amount     |
    75        | lpprov    | USD.1.1 | 1000000000 |
    76        | lpprov2   | USD.1.1 | 1000000000 |
    77        | aux1      | USD.1.1 | 1000000000 |
    78        | aux2      | USD.1.1 | 1000000000 |
    79        | aux3      | USD.1.1 | 1000000000 |
    80        | aux4      | USD.1.1 | 1000000000 |
    81        | referrer1 | USD.1.1 | 1000000000 |
    82        | referee1  | USD.1.1 | 1000000000 |
    83        | referee2  | USD.1.1 | 1000000000 |
    84        | ptbuy     | USD.1.1 | 1000000000 |
    85        | ptsell    | USD.1.1 | 1000000000 |
    86  
    87      # Exit the opening auction
    88      Given the parties submit the following liquidity provision:
    89        | id  | party   | market id   | commitment amount | fee  | lp type    |
    90        | lp1 | lpprov  | ETH/USD.1.1 | 1000000           | 0.01 | submission |
    91        | lp2 | lpprov2 | ETH/USD.1.2 | 1000000           | 0.01 | submission |
    92      And the parties place the following pegged iceberg orders:
    93        | party   | market id   | peak size | minimum visible size | side | pegged reference | volume | offset |
    94        | lpprov  | ETH/USD.1.1 | 5000      | 1000                 | buy  | BID              | 10000  | 1      |
    95        | lpprov  | ETH/USD.1.1 | 5000      | 1000                 | sell | ASK              | 10000  | 1      |
    96        | lpprov2 | ETH/USD.1.2 | 5000      | 1000                 | buy  | BID              | 10000  | 1      |
    97        | lpprov2 | ETH/USD.1.2 | 5000      | 1000                 | sell | ASK              | 10000  | 1      |
    98      When the parties place the following orders:
    99        | party | market id   | side | volume | price | resulting trades | type       | tif     |
   100        | aux1  | ETH/USD.1.1 | buy  | 1      | 990   | 0                | TYPE_LIMIT | TIF_GTC |
   101        | aux1  | ETH/USD.1.1 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   102        | aux2  | ETH/USD.1.1 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   103        | aux2  | ETH/USD.1.1 | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
   104        | aux3  | ETH/USD.1.2 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   105        | aux3  | ETH/USD.1.2 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   106        | aux4  | ETH/USD.1.2 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   107        | aux4  | ETH/USD.1.2 | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
   108      Then the opening auction period ends for market "ETH/USD.1.1"
   109      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/USD.1.1"
   110      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/USD.1.2"
   111  
   112      # Create the referral set and codes
   113      Given the parties create the following referral codes:
   114        | party     | code            | is_team | team  |
   115        | referrer1 | referral-code-1 | true    | team1 |
   116      And the parties apply the following referral codes:
   117        | party    | code            | is_team | team  |
   118        | referee1 | referral-code-1 | true    | team1 |
   119  
   120      And the team "team1" has the following members:
   121        | party     |
   122        | referrer1 |
   123        | referee1  |
   124  
   125  
   126    Scenario: When in continuous trading, fees discounted correctly when party has non-zero referral and volume discount factors (0029-FEES-032)
   127      # Expectation: referral discount applied before volume discount
   128  
   129      Given the parties place the following orders:
   130        | party    | market id   | side | volume | price | resulting trades | type       | tif     |
   131        | aux1     | ETH/USD.1.1 | buy  | 20     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   132        | referee1 | ETH/USD.1.1 | sell | 20     | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
   133      When the network moves ahead "2" epochs
   134      Then the referral set stats for code "referral-code-1" at epoch "2" should have a running volume of 2000:
   135        | party    | reward infra factor | reward maker factor | reward liquidity factor | discount infra factor | discount maker factor | discount liquidity factor |
   136        | referee1 | 0                   | 0                   | 0                       | 0.11                  | 0.12                  | 0.13                      |
   137      And the party "referee1" has the following taker notional "2000"
   138      And the party "referee1" has the following discount infra factor "0.11"
   139      And the party "referee1" has the following discount liquidity factor "0.12"
   140      And the party "referee1" has the following discount maker factor "0.13"
   141  
   142      Given the parties place the following orders:
   143        | party    | market id   | side | volume | price | resulting trades | type       | tif     |
   144        | aux1     | ETH/USD.1.1 | buy  | 100    | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   145        | referee1 | ETH/USD.1.1 | sell | 100    | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
   146      When the following trades should be executed:
   147        | buyer | price | size | seller   |
   148        | aux1  | 1000  | 100  | referee1 |
   149      Then the following transfers should happen:
   150        | from     | to     | from account         | to account                       | market id   | amount | asset   |
   151        | referee1 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER          | ETH/USD.1.1 | 77     | USD.1.1 |
   152        | referee1 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/USD.1.1 | 77     | USD.1.1 |
   153        | referee1 |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |             | 80     | USD.1.1 |
   154  
   155      # Additionally check if referral discount fully discounts fees, core does not panic when trying to apply volume discounts
   156      Given the network moves ahead "1" epochs
   157      Then the referral set stats for code "referral-code-1" at epoch "3" should have a running volume of 12000:
   158        | party    | reward infra factor | reward maker factor | reward liquidity factor | discount infra factor | discount maker factor | discount liquidity factor |
   159        | referee1 | 0                   | 0                   | 0                       | 1.0                   | 1.0                   | 1.0                       |
   160      And the party "referee1" has the following taker notional "12000"
   161      And the party "referee1" has the following discount infra factor "0.11"
   162      And the party "referee1" has the following discount liquidity factor "0.12"
   163      And the party "referee1" has the following discount maker factor "0.13"
   164  
   165      Given the parties place the following orders:
   166        | party    | market id   | side | volume | price | resulting trades | type       | tif     |
   167        | aux1     | ETH/USD.1.1 | buy  | 100    | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   168        | referee1 | ETH/USD.1.1 | sell | 100    | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
   169      When the following trades should be executed:
   170        | buyer | price | size | seller   |
   171        | aux1  | 1000  | 100  | referee1 |
   172      Then the following transfers should happen:
   173        | from     | to     | from account         | to account                       | market id   | amount | asset   |
   174        | referee1 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER          | ETH/USD.1.1 | 0      | USD.1.1 |
   175        | referee1 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/USD.1.1 | 0      | USD.1.1 |
   176        | referee1 |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |             | 0      | USD.1.1 |
   177  
   178    Scenario: When exiting an auction, fees discounted correctly when party has non-zero referral and volume discount factors (0029-FEES-033)
   179      # Expectation: fee should be split between buyer and seller, referral discount applied before volume discount
   180  
   181      When the parties place the following orders:
   182        | party    | market id   | side | volume | price | resulting trades | type       | tif     |
   183        | aux3     | ETH/USD.1.2 | buy  | 20     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   184        | referee1 | ETH/USD.1.2 | sell | 20     | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
   185      Then the market data for the market "ETH/USD.1.2" should be:
   186        | mark price | trading mode            | target stake | supplied stake | open interest | horizon | min bound | max bound |
   187        | 1000       | TRADING_MODE_CONTINUOUS | 7469         | 1000000        | 21            | 3600    | 973       | 1027      |
   188      When the network moves ahead "2" epochs
   189      Then the referral set stats for code "referral-code-1" at epoch "2" should have a running volume of 2000:
   190        | party    | reward infra factor | reward maker factor | reward liquidity factor | discount infra factor | discount maker factor | discount liquidity factor |
   191        | referee1 | 0                   | 0                   | 0                       | 0.11                  | 0.12                  | 0.13                      |
   192      And the party "referee1" has the following taker notional "2000"
   193      And the party "referee1" has the following discount infra factor "0.11"
   194      And the party "referee1" has the following discount liquidity factor "0.12"
   195      And the party "referee1" has the following discount maker factor "0.13"
   196  
   197      When the parties place the following orders:
   198        | party  | market id   | side | volume | price | resulting trades | type       | tif     |
   199        | ptbuy  | ETH/USD.1.2 | buy  | 2      | 970   | 0                | TYPE_LIMIT | TIF_GTC |
   200        | ptsell | ETH/USD.1.2 | sell | 2      | 970   | 0                | TYPE_LIMIT | TIF_GTC |
   201      Then the market data for the market "ETH/USD.1.2" should be:
   202        | mark price | trading mode                    | auction trigger       | target stake | supplied stake | open interest | auction end |
   203        | 1000       | TRADING_MODE_MONITORING_AUCTION | AUCTION_TRIGGER_PRICE | 7935         | 1000000        | 21            | 15          |
   204      ## Triger price auction
   205      # Cancel the liquidity commitment triggering an auction
   206      And the network moves ahead "1" epochs
   207      And the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/USD.1.2"
   208      When the parties place the following orders:
   209        | party    | market id   | side | volume | price | resulting trades | type       | tif     |
   210        | aux3     | ETH/USD.1.2 | buy  | 200    | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   211        | referee1 | ETH/USD.1.2 | sell | 200    | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   212      And the network moves ahead "1" epochs
   213      Then debug trades
   214      Then the following trades should be executed:
   215        | buyer | price | size | seller   |
   216        | aux3  | 1000  | 198  | referee1 |
   217        | aux3  | 1000  | 2    | ptsell   |
   218      And the following transfers should happen:
   219        | from     | to     | from account         | to account                       | market id   | amount | asset   |
   220        | referee1 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/USD.1.2 | 77     | USD.1.1 |
   221        | referee1 |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |             | 80     | USD.1.1 |