code.vegaprotocol.io/vega@v0.79.0/core/integration/features/amm/11504-panic-empty-curve.feature (about) 1 Feature: Attempt to replicate a bug in vAMM 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 @VAMM 100 Scenario: AMM holds a long position, there should be no more buy orders created, when submitting a sell order at a lower price, a panic seemingly can occur. 101 And the market data for the market "ETH/MAR22" should be: 102 | mark price | trading mode | mid price | static mid price | best offer price | best bid price | 103 | 100 | TRADING_MODE_CONTINUOUS | 100 | 100 | 101 | 99 | 104 When the parties place the following orders: 105 | party | market id | side | volume | price | resulting trades | type | tif | 106 | party4 | ETH/MAR22 | buy | 500 | 155 | 1 | TYPE_LIMIT | TIF_GTC | 107 # see the trades that make the vAMM go short 108 Then the following trades should be executed: 109 | buyer | price | size | seller | is amm | 110 | party4 | 122 | 291 | vamm1-id | true | 111 And the market data for the market "ETH/MAR22" should be: 112 | mark price | trading mode | mid price | static mid price | best offer price | best bid price | 113 | 100 | TRADING_MODE_CONTINUOUS | 157 | 157 | 160 | 155 | 114 115 # trying to trade again causes no trades because the AMM has no more volume 116 When the parties place the following orders: 117 | party | market id | side | volume | price | resulting trades | type | tif | 118 | party4 | ETH/MAR22 | buy | 500 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 119 120 # the AMM's mid price has moved to 150, but it has no volume +150 so that best offer comes from the orderbook of 160 121 Then the market data for the market "ETH/MAR22" should be: 122 | mark price | trading mode | mid price | static mid price | best offer price | best bid price | 123 | 100 | TRADING_MODE_CONTINUOUS | 157 | 157 | 160 | 155 | 124 125 When the network moves ahead "1" blocks 126 Then the parties should have the following profit and loss: 127 | party | volume | unrealised pnl | realised pnl | is amm | 128 | party4 | 291 | 0 | 0 | | 129 | vamm1-id | -291 | 0 | 0 | true | 130 # Notional value therefore is 317 * 122 131 And the market data for the market "ETH/MAR22" should be: 132 | mark price | trading mode | mid price | static mid price | best offer price | best bid price | 133 | 122 | TRADING_MODE_CONTINUOUS | 157 | 157 | 160 | 155 | 134 135 # vAMM receives fees, but loses out in the MTM settlement 136 And the following transfers should happen: 137 | from | from account | to | to account | market id | amount | asset | is amm | type | 138 | | ACCOUNT_TYPE_FEES_MAKER | vamm1-id | ACCOUNT_TYPE_GENERAL | ETH/MAR22 | 143 | USD | true | TRANSFER_TYPE_MAKER_FEE_RECEIVE | 139 | vamm1-id | ACCOUNT_TYPE_GENERAL | vamm1-id | ACCOUNT_TYPE_MARGIN | ETH/MAR22 | 74548 | USD | true | TRANSFER_TYPE_MARGIN_LOW | 140 141 When the parties place the following orders: 142 | party | market id | side | volume | price | resulting trades | type | tif | 143 | party5 | ETH/MAR22 | buy | 1 | 160 | 1 | TYPE_LIMIT | TIF_GTC | 144 Then the following trades should be executed: 145 | buyer | price | size | seller | is amm | 146 | party5 | 160 | 1 | lp1 | false | 147 148 When the network moves ahead "1" blocks 149 Then the parties should have the following profit and loss: 150 | party | volume | unrealised pnl | realised pnl | is amm | 151 | party4 | 291 | 11058 | 0 | | 152 | party5 | 1 | 0 | 0 | | 153 | lp1 | -1 | 0 | 0 | | 154 | vamm1-id | -291 | -11058 | 0 | true | 155 156 # Now the same buy use a market order 157 When the parties place the following orders: 158 | party | market id | side | volume | price | resulting trades | type | tif | 159 | party5 | ETH/MAR22 | buy | 2 | 0 | 1 | TYPE_MARKET | TIF_FOK | 160 Then the following trades should be executed: 161 | buyer | price | size | seller | is amm | 162 | party5 | 160 | 2 | lp1 | false | 163 164 When the network moves ahead "1" blocks 165 Then the parties should have the following profit and loss: 166 | party | volume | unrealised pnl | realised pnl | is amm | 167 | party4 | 291 | 11058 | 0 | | 168 | party5 | 3 | 0 | 0 | | 169 | lp1 | -3 | 0 | 0 | | 170 | vamm1-id | -291 | -11058 | 0 | true | 171 172 When the parties cancel the following AMM: 173 | party | market id | method | 174 | vamm1 | ETH/MAR22 | METHOD_IMMEDIATE | 175 Then the AMM pool status should be: 176 | party | market id | amount | status | base | lower bound | upper bound | lower leverage | upper leverage | 177 | vamm1 | ETH/MAR22 | 100000 | STATUS_CANCELLED | 100 | 85 | 150 | 4 | 4 | 178 And the parties submit the following AMM: 179 | party | market id | amount | slippage | base | lower bound | lower leverage | proposed fee | 180 | vamm1 | ETH/MAR22 | 99999 | 0.1 | 100 | 85 | 4 | 0.01 | 181 Then the AMM pool status should be: 182 | party | market id | amount | status | base | lower bound | lower leverage | 183 | vamm1 | ETH/MAR22 | 99999 | STATUS_ACTIVE | 100 | 85 | 4 | 184 And set the following AMM sub account aliases: 185 | party | market id | alias | 186 | vamm1 | ETH/MAR22 | vamm2-id | 187 And the following transfers should happen: 188 | from | from account | to | to account | market id | amount | asset | is amm | type | 189 | vamm1 | ACCOUNT_TYPE_GENERAL | vamm2-id | ACCOUNT_TYPE_GENERAL | | 99999 | USD | true | TRANSFER_TYPE_AMM_LOW | 190 ## This is what we're after 191 Then the parties should have the following profit and loss: 192 | party | volume | unrealised pnl | realised pnl | is amm | 193 | party4 | 291 | 11058 | 0 | | 194 | party1 | 1 | 60 | 0 | | 195 | party5 | 3 | 0 | 0 | | 196 | lp1 | -3 | 0 | 0 | | 197 | vamm1-id | 0 | 0 | -11058 | true | 198 199 # Now the same but use a sell order that is outside of the range 200 When the parties place the following orders: 201 | party | market id | side | volume | price | resulting trades | type | tif | 202 | party1 | ETH/MAR22 | sell | 1 | 150 | 1 | TYPE_LIMIT | TIF_GTC | 203 Then the following trades should be executed: 204 | buyer | price | size | seller | is amm | 205 | party4 | 155 | 1 | party1 | false | 206 207 When the network moves ahead "1" blocks 208 Then the parties should have the following profit and loss: 209 | party | volume | unrealised pnl | realised pnl | is amm | 210 | party4 | 292 | 9603 | 0 | | 211 | party1 | 0 | 0 | 55 | | 212 | party5 | 3 | -15 | 0 | | 213 | lp1 | -3 | 15 | 0 | | 214 | vamm1-id | 0 | 0 | -11058 | true | 215 216 When the network moves ahead "1" blocks 217 Then the parties place the following orders: 218 | party | market id | side | volume | price | resulting trades | type | tif | 219 | party4 | ETH/MAR22 | buy | 100 | 90 | 0 | TYPE_LIMIT | TIF_GTC | 220 | party4 | ETH/MAR22 | sell | 100 | 100 | 0 | TYPE_LIMIT | TIF_GTC |