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

     1  Feature: Test vAMM cancellation by reduce-only from long.
     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                     | 1     |
    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   | 1000000 |
    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 | 100000 | 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 | 100000 | 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 |           | 100000 | USD   | true   | TRANSFER_TYPE_AMM_LOW |
    98  
    99  
   100    @VAMM
   101    Scenario: 0090-VAMM-020: If a vAMM is cancelled and set in Reduce-Only mode when it is currently long, then It creates no further buy orders even if the current price is above the configured lower price. When one of it's sell orders is executed it still does not produce buy orders, and correctly quotes sell orders from a higher price. When the position reaches 0 the vAMM is closed and all funds are released to the user after the next mark to market.
   102      When the parties place the following orders:
   103        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   104        | party4 | ETH/MAR22 | sell | 350    | 90    | 1                | TYPE_LIMIT | TIF_GTC |
   105      # see the trades that make the vAMM go long
   106      Then the following trades should be executed:
   107        | buyer    | price | size | seller | is amm |
   108        | vamm1-id | 95    | 350  | party4 | true   |
   109      And the network moves ahead "1" blocks
   110      Then the market data for the market "ETH/MAR22" should be:
   111        | mark price | trading mode            | mid price | static mid price |
   112        | 95         | TRADING_MODE_CONTINUOUS | 90        | 90               |
   113  	Then the parties should have the following profit and loss:
   114        | party    | volume | unrealised pnl | realised pnl | is amm |
   115        | party4   | -350   | 0              | 0            |        |
   116        | vamm1-id | 350    | 0              | 0            | true   |
   117      And the following transfers should happen:
   118        | from     | from account            | to       | to account           | market id | amount | asset | is amm | type                            |
   119        |          | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 133    | USD   | true   | TRANSFER_TYPE_MAKER_FEE_RECEIVE |
   120        | vamm1-id | ACCOUNT_TYPE_GENERAL    | vamm1-id | ACCOUNT_TYPE_MARGIN  | ETH/MAR22 | 64462  | USD   | true   | TRANSFER_TYPE_MARGIN_LOW        |
   121      And the parties should have the following account balances:
   122        | party    | asset | market id | general | margin | is amm |
   123        | vamm1    | USD   |           | 900000  |        |        |
   124        | vamm1-id | USD   | ETH/MAR22 | 35671   | 64462  | true   |
   125      And the market data for the market "ETH/MAR22" should be:
   126        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   127        | 95         | TRADING_MODE_CONTINUOUS | 90        | 90               | 91               | 89             |
   128  
   129      # Next: cancel the vAMM with reduce-only
   130      When the parties cancel the following AMM:
   131        | party | market id | method             |
   132        | vamm1 | ETH/MAR22 | METHOD_REDUCE_ONLY |
   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 | 100000 | STATUS_REDUCE_ONLY | 100  | 85          | 150         | 4              | 4              |
   136      # Check if the vAMM doesn't place any more buy orders: submit sell orders at previous best bid, ask, and mid prices:
   137      When the parties place the following orders:
   138        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   139        | party4 | ETH/MAR22 | sell | 10     | 89    | 0                | TYPE_LIMIT | TIF_GTC |
   140        | party4 | ETH/MAR22 | sell | 10     | 90    | 0                | TYPE_LIMIT | TIF_GTC |
   141        | party4 | ETH/MAR22 | sell | 10     | 91    | 0                | TYPE_LIMIT | TIF_GTC |
   142      Then the market data for the market "ETH/MAR22" should be:
   143        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   144        | 95         | TRADING_MODE_CONTINUOUS | 64        | 64               | 89               | 40             |
   145      
   146      # Now start checking if the vAMM still quotes sell orders
   147      When the parties place the following orders:
   148        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   149        | party5 | ETH/MAR22 | buy  | 280    | 110   | 5                | TYPE_LIMIT | TIF_GTC |
   150      Then the following trades should be executed:
   151        | buyer  | price | size | seller   | is amm |
   152        | party5 | 89    | 10   | party4   |        |
   153        | party5 | 90    | 10   | party4   |        |
   154        | party5 | 90    | 19   | vamm1-id | true   |
   155        | party5 | 91    | 10   | party4   |        |
   156        | party5 | 90    | 19   | vamm1-id | true   |
   157        | party5 | 94    | 231  | vamm1-id | true   |
   158  
   159      # check the state of the market, trigger MTM settlement and check balances before closing out the last 100 for the vAMM
   160      When the network moves ahead "1" blocks
   161  	  Then the parties should have the following profit and loss:
   162        | party    | volume | unrealised pnl | realised pnl | is amm |
   163        | party4   | -380   | 230            | 0            |        |
   164        | party5   | 280    | 196            | 0            |        |
   165        | vamm1-id | 100    | -100           | -326         | true   |
   166      # vAMM is still quoting bid price, though it is in reduce-only mode, and therefore doesn't place those orders.
   167      # The best bid should be 40 here?
   168      And the market data for the market "ETH/MAR22" should be:
   169        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   170        | 94         | TRADING_MODE_CONTINUOUS | 69        | 69               | 98               | 40             |
   171      # vAMM receives some fees, but pays MTM loss, excess margin is released
   172      And the following transfers should happen:
   173        | from     | from account            | to       | to account              | market id | amount | asset | is amm | type                            |
   174        |          | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL    | ETH/MAR22 | 87     | USD   | true   | TRANSFER_TYPE_MAKER_FEE_RECEIVE |
   175        | vamm1-id | ACCOUNT_TYPE_MARGIN     |          | ACCOUNT_TYPE_SETTLEMENT | ETH/MAR22 | 426    | USD   | true   | TRANSFER_TYPE_MTM_LOSS          |
   176        | vamm1-id | ACCOUNT_TYPE_MARGIN     | vamm1-id | ACCOUNT_TYPE_GENERAL    | ETH/MAR22 | 45811  | USD   | true   | TRANSFER_TYPE_MARGIN_HIGH       |
   177      # After receiving fees, and excess margin is correctly released, the balances of the vAMM sub-accounts match the position:
   178      And the parties should have the following account balances:
   179        | party    | asset | market id | general | margin | is amm |
   180        | vamm1    | USD   |           | 900000  |        |        |
   181        | vamm1-id | USD   | ETH/MAR22 | 81576   | 18225  | true   |
   182  
   183      # Now make sure the vAMM, though clearly having sufficient balance to increase its position, still doesn't place any buy orders (reduce only check 2)
   184      # Like before, place orders at mid, offer, and bid prices
   185      When the parties place the following orders:
   186        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   187        | party4 | ETH/MAR22 | sell | 10     | 96    | 0                | TYPE_LIMIT | TIF_GTC | p4-c1     |
   188        | party4 | ETH/MAR22 | sell | 10     | 97    | 0                | TYPE_LIMIT | TIF_GTC | p4-c2     |
   189        | party4 | ETH/MAR22 | sell | 10     | 98    | 0                | TYPE_LIMIT | TIF_GTC | p4-c3     |
   190      # we've confirmed the vAMM does not reduce its position at all, so cancel these orders to keep things simple
   191      Then the parties cancel the following orders:
   192        | party  | reference |
   193        | party4 | p4-c1     |
   194        | party4 | p4-c2     |
   195        | party4 | p4-c3     |
   196      # party5 places a buy order large enough to trade with party4 and reduce the vAMM position down to 0, and no more.
   197      # we'll do a  v2 of this test where this buy order is "over-sized" to ensure the vAMM doesn't flip from long to short.
   198      And the parties place the following orders:
   199        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   200        | party5 | ETH/MAR22 | buy  | 100    | 110   | 1                | TYPE_LIMIT | TIF_GTC |
   201      Then the following trades should be executed:
   202        | buyer  | price | size | seller   | is amm |
   203        | party5 | 98    | 100  | vamm1-id | true   |
   204      # Confirm the vAMM is no longer quoting anything
   205      And the market data for the market "ETH/MAR22" should be:
   206        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   207        | 94         | TRADING_MODE_CONTINUOUS | 100       | 100              | 160              | 40             |
   208  
   209      # Check the final PnL for the vAMM, check the transfers and balances
   210      When the network moves ahead "1" blocks
   211  	Then the parties should have the following profit and loss:
   212        | party    | volume | unrealised pnl | realised pnl | is amm |
   213        | party4   | -380   | -1290          | 0            |        |
   214        | party5   | 380    | 1316           | 0            |        |
   215        | vamm1-id | 0      | 0              | -26          | true   |
   216      And the AMM pool status should be:
   217        | party | market id | amount | status           | base | lower bound | upper bound | lower leverage | upper leverage |
   218        | vamm1 | ETH/MAR22 | 100000 | STATUS_CANCELLED | 100  | 85          | 150         | 4              | 4              |
   219      And the market data for the market "ETH/MAR22" should be:
   220        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   221        | 98         | TRADING_MODE_CONTINUOUS | 100       | 100              | 160              | 40             |
   222      And the following transfers should happen:
   223         | from     | from account            | to       | to account           | market id | amount | asset | is amm | type                                 |
   224         |          | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 40     | USD   | true   | TRANSFER_TYPE_MAKER_FEE_RECEIVE      |
   225         |          | ACCOUNT_TYPE_SETTLEMENT | vamm1-id | ACCOUNT_TYPE_MARGIN  | ETH/MAR22 | 400    | USD   | true   | TRANSFER_TYPE_MTM_WIN                |
   226         | vamm1-id | ACCOUNT_TYPE_MARGIN     | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 18625  | USD   | true   | TRANSFER_TYPE_MARGIN_HIGH            |
   227         | vamm1-id | ACCOUNT_TYPE_GENERAL    | vamm1    | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 100241 | USD   | true   | TRANSFER_TYPE_AMM_RELEASE            |
   228      And the parties should have the following account balances:
   229        | party    | asset | market id | general | margin | is amm |
   230        | vamm1    | USD   |           | 1000241 |        |        |
   231        | vamm1-id | USD   | ETH/MAR22 | 0       | 0      | true   |
   232  
   233    @VAMM
   234    Scenario: 0090-VAMM-020: Same as the test above, only the final buy order that moves the vAMM position to 0 is more than big enough, and doesn't cause the vAMM to flip position from long to short.
   235      When the parties place the following orders:
   236        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   237        | party4 | ETH/MAR22 | sell | 350    | 90    | 1                | TYPE_LIMIT | TIF_GTC |
   238      # see the trades that make the vAMM go long
   239      Then the following trades should be executed:
   240        | buyer    | price | size | seller | is amm |
   241        | vamm1-id | 95    | 350  | party4 | true   |
   242      And the network moves ahead "1" blocks
   243      Then the market data for the market "ETH/MAR22" should be:
   244        | mark price | trading mode            | mid price | static mid price |
   245        | 95         | TRADING_MODE_CONTINUOUS | 90        | 90               |
   246  	Then the parties should have the following profit and loss:
   247        | party    | volume | unrealised pnl | realised pnl | is amm |
   248        | party4   | -350   | 0              | 0            |        |
   249        | vamm1-id | 350    | 0              | 0            | true   |
   250      And the following transfers should happen:
   251        | from     | from account            | to       | to account           | market id | amount | asset | is amm | type                            |
   252        |          | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 133    | USD   | true   | TRANSFER_TYPE_MAKER_FEE_RECEIVE |
   253        | vamm1-id | ACCOUNT_TYPE_GENERAL    | vamm1-id | ACCOUNT_TYPE_MARGIN  | ETH/MAR22 | 64462  | USD   | true   | TRANSFER_TYPE_MARGIN_LOW        |
   254      And the parties should have the following account balances:
   255        | party    | asset | market id | general | margin | is amm |
   256        | vamm1    | USD   |           | 900000  |        |        |
   257        | vamm1-id | USD   | ETH/MAR22 | 35671   | 64462  | true   |
   258      And the market data for the market "ETH/MAR22" should be:
   259        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   260        | 95         | TRADING_MODE_CONTINUOUS | 90        | 90               | 91               | 89             |
   261  
   262      # Next: cancel the vAMM with reduce-only
   263      When the parties cancel the following AMM:
   264        | party | market id | method             |
   265        | vamm1 | ETH/MAR22 | METHOD_REDUCE_ONLY |
   266      Then the AMM pool status should be:
   267        | party | market id | amount | status             | base | lower bound | upper bound | lower leverage | upper leverage |
   268        | vamm1 | ETH/MAR22 | 100000 | STATUS_REDUCE_ONLY | 100  | 85          | 150         | 4              | 4              |
   269      # Check if the vAMM doesn't place any more buy orders: submit sell orders at previous best bid, ask, and mid prices:
   270      When the parties place the following orders:
   271        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   272        | party4 | ETH/MAR22 | sell | 10     | 89    | 0                | TYPE_LIMIT | TIF_GTC |
   273        | party4 | ETH/MAR22 | sell | 10     | 90    | 0                | TYPE_LIMIT | TIF_GTC |
   274        | party4 | ETH/MAR22 | sell | 10     | 91    | 0                | TYPE_LIMIT | TIF_GTC |
   275      Then the market data for the market "ETH/MAR22" should be:
   276        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   277        | 95         | TRADING_MODE_CONTINUOUS | 64        | 64               | 89               | 40             |
   278      And clear trade events
   279      # Now start checking if the vAMM still quotes sell orders
   280      When the parties place the following orders:
   281        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   282        | party5 | ETH/MAR22 | buy  | 280    | 110   | 5                | TYPE_LIMIT | TIF_GTC |
   283      Then the following trades should be executed:
   284        | buyer  | price | size | seller   | is amm |
   285        | party5 | 89    | 10   | party4   |        |
   286        | party5 | 90    | 10   | party4   |        |
   287        | party5 | 90    | 19   | vamm1-id | true   |
   288        | party5 | 91    | 10   | party4   |        |
   289        | party5 | 90    | 19   | vamm1-id | true   |
   290        | party5 | 94    | 231  | vamm1-id | true   |
   291  
   292      # check the state of the market, trigger MTM settlement and check balances before closing out the last 100 for the vAMM
   293      When the network moves ahead "1" blocks
   294  	  Then the parties should have the following profit and loss:
   295        | party    | volume | unrealised pnl | realised pnl | is amm |
   296        | party4   | -380   | 230            | 0            |        |
   297        | party5   | 280    | 196            | 0            |        |
   298        | vamm1-id | 100    | -100           | -326         | true   |
   299      # vAMM is still quoting bid price, though it is in reduce-only mode, and therefore doesn't place those orders.
   300      # The best bid should be 40 here?
   301      And the market data for the market "ETH/MAR22" should be:
   302        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   303        | 94         | TRADING_MODE_CONTINUOUS | 69        | 69               | 98               | 40             |
   304      # vAMM receives some fees, but pays MTM loss, excess margin is released
   305      And the following transfers should happen:
   306        | from     | from account            | to       | to account              | market id | amount | asset | is amm | type                            |
   307        |          | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL    | ETH/MAR22 | 87     | USD   | true   | TRANSFER_TYPE_MAKER_FEE_RECEIVE |
   308        | vamm1-id | ACCOUNT_TYPE_MARGIN     |          | ACCOUNT_TYPE_SETTLEMENT | ETH/MAR22 | 426    | USD   | true   | TRANSFER_TYPE_MTM_LOSS          |
   309        | vamm1-id | ACCOUNT_TYPE_MARGIN     | vamm1-id | ACCOUNT_TYPE_GENERAL    | ETH/MAR22 | 45811  | USD   | true   | TRANSFER_TYPE_MARGIN_HIGH       |
   310      # After receiving fees, and excess margin is correctly released, the balances of the vAMM sub-accounts match the position:
   311      And the parties should have the following account balances:
   312        | party    | asset | market id | general | margin | is amm |
   313        | vamm1    | USD   |           | 900000  |        |        |
   314        | vamm1-id | USD   | ETH/MAR22 | 81576   | 18225  | true   |
   315  
   316      # Now make sure the vAMM, though clearly having sufficient balance to increase its position, still doesn't place any buy orders (reduce only check 2)
   317      # Like before, place orders at mid, offer, and bid prices
   318      When the parties place the following orders:
   319        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   320        | party4 | ETH/MAR22 | sell | 10     | 96    | 0                | TYPE_LIMIT | TIF_GTC | p4-c1     |
   321        | party4 | ETH/MAR22 | sell | 10     | 97    | 0                | TYPE_LIMIT | TIF_GTC | p4-c2     |
   322        | party4 | ETH/MAR22 | sell | 10     | 98    | 0                | TYPE_LIMIT | TIF_GTC | p4-c3     |
   323      # we've confirmed the vAMM does not reduce its position at all, so cancel these orders to keep things simple
   324      Then the parties cancel the following orders:
   325        | party  | reference |
   326        | party4 | p4-c1     |
   327        | party4 | p4-c2     |
   328        | party4 | p4-c3     |
   329      # party5 places a buy order large enough to trade with party4 and reduce the vAMM position down to 0, and more, vAMM does not trade to move from long to short, it stays at 0.
   330      And the parties place the following orders:
   331        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   332        | party5 | ETH/MAR22 | buy  | 150    | 110   | 1                | TYPE_LIMIT | TIF_GTC |
   333      Then the following trades should be executed:
   334        | buyer  | price | size | seller   | is amm |
   335        | party5 | 98    | 100  | vamm1-id | true   |
   336      # Confirm the vAMM is no longer quoting anything
   337      And the market data for the market "ETH/MAR22" should be:
   338        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   339        | 94         | TRADING_MODE_CONTINUOUS | 135       | 135              | 160              | 110            |
   340  
   341      # Check the final PnL for the vAMM, check the transfers and balances
   342      When the network moves ahead "1" blocks
   343  	Then the parties should have the following profit and loss:
   344        | party    | volume | unrealised pnl | realised pnl | is amm |
   345        | party4   | -380   | -1290          | 0            |        |
   346        | party5   | 380    | 1316           | 0            |        |
   347        | vamm1-id | 0      | 0              | -26          | true   |
   348      And the AMM pool status should be:
   349        | party | market id | amount | status           | base | lower bound | upper bound | lower leverage | upper leverage |
   350        | vamm1 | ETH/MAR22 | 100000 | STATUS_CANCELLED | 100  | 85          | 150         | 4              | 4              |
   351      And the market data for the market "ETH/MAR22" should be:
   352        | mark price | trading mode            | mid price | static mid price | best offer price | best bid price |
   353        | 98         | TRADING_MODE_CONTINUOUS | 135       | 135              | 160              | 110            |
   354      And the following transfers should happen:
   355         | from     | from account            | to       | to account           | market id | amount | asset | is amm | type                            |
   356         |          | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 40     | USD   | true   | TRANSFER_TYPE_MAKER_FEE_RECEIVE |
   357         |          | ACCOUNT_TYPE_SETTLEMENT | vamm1-id | ACCOUNT_TYPE_MARGIN  | ETH/MAR22 | 400    | USD   | true   | TRANSFER_TYPE_MTM_WIN           |
   358         | vamm1-id | ACCOUNT_TYPE_MARGIN     | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 18625  | USD   | true   | TRANSFER_TYPE_MARGIN_HIGH       |
   359         | vamm1-id | ACCOUNT_TYPE_GENERAL    | vamm1    | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 100241 | USD   | true   | TRANSFER_TYPE_AMM_RELEASE       |
   360      And the parties should have the following account balances:
   361        | party    | asset | market id | general | margin | is amm |
   362        | vamm1    | USD   |           | 1000241 |        |        |
   363        | vamm1-id | USD   | ETH/MAR22 | 0       | 0      | true   |