code.vegaprotocol.io/vega@v0.79.0/core/integration/features/amm/0090-VAMM-024-026.feature (about)

     1  Feature: When market.amm.minCommitmentQuantum is 1000, mid price of the market 100, and a user with 1000 USDT creates a vAMM with commitment 1000, base price 100, upper price 150, lower price 85 and leverage ratio at each bound 0.25
     2  
     3    Background:
     4      Given the average block duration is "1"
     5      And the margin calculator named "margin-calculator-1":
     6        | search factor | initial factor | release factor |
     7        | 1.2           | 1.5            | 1.7            |
     8      And the log normal risk model named "log-normal-risk-model":
     9        | risk aversion | tau                   | mu | r   | sigma |
    10        | 0.001         | 0.0011407711613050422 | 0  | 0.9 | 3.0   |
    11      And the liquidity monitoring parameters:
    12        | name       | triggering ratio | time window | scaling factor |
    13        | lqm-params | 1.00             | 20s         | 1              |
    14        
    15      And the following network parameters are set:
    16        | name                                                | value |
    17        | market.value.windowLength                           | 60s   |
    18        | network.markPriceUpdateMaximumFrequency             | 0s    |
    19        | limits.markets.maxPeggedOrders                      | 6     |
    20        | market.auction.minimumDuration                      | 1     |
    21        | market.fee.factors.infrastructureFee                | 0.001 |
    22        | market.fee.factors.makerFee                         | 0.004 |
    23        | spam.protection.max.stopOrdersPerMarket             | 5     |
    24        | market.liquidity.equityLikeShareFeeFraction         | 1     |
    25  	  | market.amm.minCommitmentQuantum                     | 1000  |
    26        | market.liquidity.bondPenaltyParameter               | 0.2   |
    27        | market.liquidity.stakeToCcyVolume                   | 1     |
    28        | market.liquidity.successorLaunchWindowLength        | 1h    |
    29        | market.liquidity.sla.nonPerformanceBondPenaltySlope | 0.1   |
    30        | market.liquidity.sla.nonPerformanceBondPenaltyMax   | 0.6   |
    31        | validators.epoch.length                             | 10s   |
    32        | market.liquidity.earlyExitPenalty                   | 0.25  |
    33        | market.liquidity.maximumLiquidityFeeFactorLevel     | 0.25  |
    34      #risk factor short:3.5569036
    35      #risk factor long:0.801225765
    36      And the following assets are registered:
    37        | id  | decimal places |
    38        | USD | 0              |
    39      And the fees configuration named "fees-config-1":
    40        | maker fee | infrastructure fee |
    41        | 0.0004    | 0.001              |
    42  
    43      And the liquidity sla params named "SLA-22":
    44        | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    45        | 0.5         | 0.6                          | 1                             | 1.0                    |
    46  
    47      And the markets:
    48        | id        | quote name | asset | liquidity monitoring | risk model            | margin calculator   | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params |
    49        | ETH/MAR22 | USD        | USD   | lqm-params           | log-normal-risk-model | margin-calculator-1 | 2                | fees-config-1 | default-none     | default-eth-for-future | 1e0                    | 0                         | SLA-22     |
    50  
    51      # Setting up the accounts and vAMM submission now is part of the background, because we'll be running scenarios 0090-VAMM-006 through 0090-VAMM-014 on this setup
    52      Given the parties deposit on asset's general account the following amount:
    53        | party  | asset | amount  |
    54        | lp1    | USD   | 1000000 |
    55        | lp2    | USD   | 1000000 |
    56        | lp3    | USD   | 1000000 |
    57        | party1 | USD   | 1000000 |
    58        | party2 | USD   | 1000000 |
    59        | party3 | USD   | 1000000 |
    60        | party4 | USD   | 1000000 |
    61        | party5 | USD   | 1000000 |
    62        | vamm1  | USD   | 30000   |
    63  
    64      When the parties submit the following liquidity provision:
    65        | id   | party | market id | commitment amount | fee   | lp type    |
    66        | lp_1 | lp1   | ETH/MAR22 | 600               | 0.02  | submission |
    67        | lp_2 | lp2   | ETH/MAR22 | 400               | 0.015 | submission |
    68      Then the network moves ahead "4" blocks
    69      And the current epoch is "0"
    70  
    71      And the parties place the following orders:
    72        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    73        | lp1    | ETH/MAR22 | buy  | 20     | 40    | 0                | TYPE_LIMIT | TIF_GTC | lp1-b     |
    74        | party1 | ETH/MAR22 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GTC |           |
    75        | party2 | ETH/MAR22 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GTC |           |
    76        | lp1    | ETH/MAR22 | sell | 10     | 160   | 0                | TYPE_LIMIT | TIF_GTC | lp1-s     |
    77      When the opening auction period ends for market "ETH/MAR22"
    78      Then the following trades should be executed:
    79        | buyer  | price | size | seller |
    80        | party1 | 100   | 1    | party2 |
    81  
    82      And the market data for the market "ETH/MAR22" should be:
    83        | mark price | trading mode            | target stake | supplied stake | open interest | ref price | mid price | static mid price |
    84        | 100        | TRADING_MODE_CONTINUOUS | 39           | 1000           | 1             | 100       | 100       | 100              |
    85      When the parties submit the following AMM:
    86        | party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | proposed fee |
    87        | vamm1 | ETH/MAR22 | 30000  | 0.1      | 100  | 85          | 150         | 4              | 4              | 0.01         |
    88      Then the AMM pool status should be:
    89        | party | market id | amount | status        | base | lower bound | upper bound | lower leverage | upper leverage |
    90        | vamm1 | ETH/MAR22 | 30000  | STATUS_ACTIVE | 100  | 85          | 150         | 4              | 4              |
    91  
    92      And set the following AMM sub account aliases:
    93        | party | market id | alias    |
    94        | vamm1 | ETH/MAR22 | vamm1-id |
    95      And the following transfers should happen:
    96        | from  | from account         | to       | to account           | market id | amount | asset | is amm | type                  |
    97        | vamm1 | ACCOUNT_TYPE_GENERAL | vamm1-id | ACCOUNT_TYPE_GENERAL |           | 30000  | USD   | true   | TRANSFER_TYPE_AMM_LOW |
    98  
    99    @VAMM
   100    Scenario: 0090-VAMM-024: If other traders trade to move the market mid price to 140 the vAMM has a short position.
   101      When the parties place the following orders:
   102        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   103        | party4 | ETH/MAR22 | buy  | 4      | 120   | 1                | TYPE_LIMIT | TIF_GTC |
   104      # see the trades that make the vAMM go short
   105  
   106      Then the following trades should be executed:
   107        | buyer  | price | size | seller   | is amm |
   108        | party4 | 100   | 4    | vamm1-id | true   |
   109  
   110      When the network moves ahead "1" blocks
   111      Then the market data for the market "ETH/MAR22" should be:
   112        | mark price | trading mode            | mid price | static mid price |
   113        | 100        | TRADING_MODE_CONTINUOUS | 102       | 102              |
   114      And the parties should have the following profit and loss:
   115        | party    | volume | unrealised pnl | realised pnl | is amm |
   116        | party4   | 4      | 0              | 0            |        |
   117        | vamm1-id | -4     | 0              | 0            | true   |
   118      And the AMM pool status should be:
   119        | party | market id | amount | status        | base | lower bound | upper bound | lower leverage | upper leverage |
   120        | vamm1 | ETH/MAR22 | 30000  | STATUS_ACTIVE | 100  | 85          | 150         | 4              | 4              |
   121  
   122    @VAMM
   123    Scenario: 0090-VAMM-025: If the vAMM is then amended such that it has a new base price of 140 it should attempt to place a trade to rebalance it's position to 0 at a mid price of 140. If that trade can execute with the slippage as configured in the request then the transaction is accepted.
   124      # other parties place large order between AMM base of 100 and 140
   125      And the parties place the following orders:
   126        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   127        | party4 | ETH/MAR22 | sell | 50     | 120   | 0                | TYPE_LIMIT | TIF_GTC |           |
   128  
   129      # Now amend the vAMM and see its rebasing trade happen
   130      When the parties amend the following AMM:
   131        | party | market id | slippage | base | lower bound | upper bound |  lower leverage | upper leverage |
   132        | vamm1 | ETH/MAR22 | 0.5      | 140  | 90          | 155         |  4              | 4              |
   133      Then the AMM pool status should be:
   134        | party | market id | amount | status        | base | lower bound | upper bound | lower leverage | upper leverage |
   135        | vamm1 | ETH/MAR22 | 30000  | STATUS_ACTIVE | 140  | 90          | 155         | 4              | 4              |
   136  
   137  
   138      And the following trades should be executed:
   139        | buyer    | price | size | seller | is amm |
   140        | vamm1-id | 120   | 49   | party4 | true   |
   141      # ensure the vamm closed its position
   142      When the network moves ahead "1" blocks
   143      Then the market data for the market "ETH/MAR22" should be:
   144        | mark price | trading mode            | mid price | static mid price |
   145        | 120        | TRADING_MODE_CONTINUOUS | 119       | 119              |
   146      And the parties should have the following profit and loss:
   147        | party    | volume | unrealised pnl | realised pnl | is amm |
   148        | party4   | -49    | 0              | 0            |        |
   149        | vamm1-id | 49     | 0              | 0            | true   |
   150  
   151    @VAMM
   152    Scenario: 0090-VAMM-026: If the trade cannot execute with the slippage as configured in the request then the transaction is rejected and no changes to the vAMM are made.
   153      When the parties place the following orders:
   154        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   155        | party4 | ETH/MAR22 | buy  | 4      | 120   | 1                | TYPE_LIMIT | TIF_GTC |
   156      # see the trades that make the vAMM go short
   157      Then the following trades should be executed:
   158        | buyer  | price | size | seller   | is amm |
   159        | party4 | 100   | 4    | vamm1-id | true   |
   160  
   161      When the network moves ahead "1" blocks
   162      Then the market data for the market "ETH/MAR22" should be:
   163        | mark price | trading mode            | mid price | static mid price |
   164        | 100        | TRADING_MODE_CONTINUOUS | 102       | 102              |
   165      And the parties should have the following profit and loss:
   166        | party    | volume | unrealised pnl | realised pnl | is amm |
   167        | party4   | 4      | 0              | 0            |        |
   168        | vamm1-id | -4     | 0              | 0            | true   |
   169      And the AMM pool status should be:
   170        | party | market id | amount | status        | base | lower bound | upper bound | lower leverage | upper leverage |
   171        | vamm1 | ETH/MAR22 | 30000  | STATUS_ACTIVE | 100  | 85          | 150         | 4              | 4              |
   172  
   173      # Now amend the vAMM such that there won't be enough liquidity to rebase
   174      When the parties amend the following AMM:
   175        | party | market id | amount | slippage | base | lower bound | upper bound | error                                  |
   176        | vamm1 | ETH/MAR22 | 10005  | 0.01     | 165  | 160         | 170         | not enough liquidity for AMM to rebase |
   177      # ensure the status of the vAMM remains the same (if no update event is sent, this test will pass even if the vAMM was in some way changed)
   178      Then the AMM pool status should be:
   179        | party | market id | amount | status        | base | lower bound | upper bound | lower leverage | upper leverage |
   180        | vamm1 | ETH/MAR22 | 30000  | STATUS_ACTIVE | 100  | 85          | 150         | 4              | 4              |
   181  
   182      # check that the account balances have not been updated either
   183      And the parties should have the following account balances:
   184        | party    | asset | market id | general | margin | is amm |
   185        | vamm1-id | USD   | ETH/MAR22 | 29162   | 840    | true   |
   186  
   187      # To account for a passing test caused by an event not being sent out, cancel the vAMM and check the status
   188      When the parties cancel the following AMM:
   189        | party | market id | method             |
   190        | vamm1 | ETH/MAR22 | METHOD_REDUCE_ONLY |
   191      Then the AMM pool status should be:
   192        | party | market id | amount | status             | base | lower bound | upper bound | lower leverage | upper leverage |
   193        | vamm1 | ETH/MAR22 | 30000  | STATUS_REDUCE_ONLY | 100  | 85          | 150         | 4              | 4              |