code.vegaprotocol.io/vega@v0.79.0/core/integration/features/amm/0090-VAMM-basic.feature (about) 1 Feature: vAMM rebasing when created or amended 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 | 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 oracle spec for settlement data filtering data from "0xCAFECAFE19" named "termination-oracle": 48 | property | type | binding | decimals | 49 | prices.ETH.value | TYPE_INTEGER | settlement data | 0 | 50 51 And the oracle spec for trading termination filtering data from "0xCAFECAFE19" named "termination-oracle": 52 | property | type | binding | 53 | trading.terminated | TYPE_BOOLEAN | trading termination | 54 55 And the markets: 56 | 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 | allowed empty amm levels | 57 | ETH/MAR22 | USD | USD | lqm-params | log-normal-risk-model | margin-calculator-1 | 2 | fees-config-1 | default-none | termination-oracle | 1e0 | 0 | SLA-22 | 5 | 58 59 # 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 60 Given the parties deposit on asset's general account the following amount: 61 | party | asset | amount | 62 | lp1 | USD | 1000000 | 63 | lp2 | USD | 1000000 | 64 | lp3 | USD | 1000000 | 65 | party1 | USD | 1000000 | 66 | party2 | USD | 1000000 | 67 | party3 | USD | 1000000 | 68 | party4 | USD | 1000000 | 69 | party5 | USD | 1000000 | 70 | vamm1 | USD | 1000000 | 71 | vamm2 | USD | 1000000 | 72 | vamm3 | USD | 1000000 | 73 74 75 And the parties place the following orders: 76 | party | market id | side | volume | price | resulting trades | type | tif | reference | 77 | lp1 | ETH/MAR22 | buy | 20 | 40 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | 78 | party5 | ETH/MAR22 | buy | 20 | 90 | 0 | TYPE_LIMIT | TIF_GTC | lp1-b | 79 | party1 | ETH/MAR22 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | 80 | party2 | ETH/MAR22 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | 81 When the opening auction period ends for market "ETH/MAR22" 82 Then the following trades should be executed: 83 | buyer | price | size | seller | 84 | party1 | 100 | 1 | party2 | 85 86 87 Then the parties submit the following AMM: 88 | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | 89 | vamm1 | ETH/MAR22 | 100000 | 0.05 | 100 | 95 | 105 | 0.03 | 90 Then the AMM pool status should be: 91 | party | market id | amount | status | base | lower bound | upper bound | 92 | vamm1 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 100 | 95 | 105 | 93 94 And set the following AMM sub account aliases: 95 | party | market id | alias | 96 | vamm1 | ETH/MAR22 | vamm1-id | 97 98 And the market data for the market "ETH/MAR22" should be: 99 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 100 | 100 | TRADING_MODE_CONTINUOUS | 99 | 101 | 103 | 92 | 101 102 @VAMM 103 Scenario: Incoming order at AMM best price 104 105 # AMM's has a BUY at 99 so a SELL at that price should match 106 When the parties place the following orders: 107 | party | market id | side | volume | price | resulting trades | type | tif | reference | 108 | party1 | ETH/MAR22 | sell | 1 | 99 | 1 | TYPE_LIMIT | TIF_GTC | | 109 Then the following trades should be executed: 110 | buyer | price | size | seller | is amm | 111 | vamm1-id | 99 | 1 | party1 | true | 112 113 @VAMM 114 Scenario: Incoming order at AMM best price and orderbook volume exists at that price 115 116 # AMM's has a BUY at 99 so a SELL at that price should match 117 When the parties place the following orders: 118 | party | market id | side | volume | price | resulting trades | type | tif | reference | 119 | party2 | ETH/MAR22 | buy | 100 | 99 | 0 | TYPE_LIMIT | TIF_GTC | | 120 | party1 | ETH/MAR22 | sell | 150 | 99 | 2 | TYPE_LIMIT | TIF_GTC | | 121 122 # incoming move AMM to a fair-price of 99, then we take the orderbook volume at 99 123 Then the following trades should be executed: 124 | buyer | price | size | seller | is amm | 125 | vamm1-id | 99 | 103 | party1 | true | 126 | party2 | 99 | 47 | party1 | true | 127 128 129 @VAMM 130 Scenario: Incoming order at AMM best price and orderbook volume exists at FAIR PRICE 131 132 # AMM's has a BUY at 99 so a SELL at that price should match 133 When the parties place the following orders: 134 | party | market id | side | volume | price | resulting trades | type | tif | reference | 135 | party2 | ETH/MAR22 | buy | 100 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | 136 | party1 | ETH/MAR22 | sell | 150 | 99 | 2 | TYPE_LIMIT | TIF_GTC | | 137 138 # incoming absorbs order at fair price, then we take volume from AMM 139 Then the following trades should be executed: 140 | buyer | price | size | seller | is amm | 141 | party2 | 100 | 100 | party1 | true | 142 | vamm1-id | 99 | 50 | party1 | true | 143 144 145 @VAMM 146 Scenario: Incoming order at AMM fair price and orderbook volume exists at FAIR PRICE 147 148 # AMM's has a BUY at 99 so a SELL at 100 should not match 149 When the parties place the following orders: 150 | party | market id | side | volume | price | resulting trades | type | tif | reference | 151 | party2 | ETH/MAR22 | buy | 100 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | 152 | party1 | ETH/MAR22 | sell | 150 | 100 | 1 | TYPE_LIMIT | TIF_GTC | | 153 154 # incoming absorbs order at fair price, then we take volume from AMM 155 Then the following trades should be executed: 156 | buyer | price | size | seller | is amm | 157 | party2 | 100 | 100 | party1 | true | 158 159 @VAMM 160 Scenario: Incoming order at AMM fair price and orderbook volume exists at FAIR PRICE and at AMM best price 161 When the parties place the following orders: 162 | party | market id | side | volume | price | resulting trades | type | tif | reference | 163 | party2 | ETH/MAR22 | buy | 50 | 100 | 0 | TYPE_LIMIT | TIF_GTC | | 164 | party2 | ETH/MAR22 | buy | 50 | 99 | 0 | TYPE_LIMIT | TIF_GTC | | 165 | party1 | ETH/MAR22 | sell | 200 | 99 | 3 | TYPE_LIMIT | TIF_GTC | | 166 167 # incoming absorbs order at fair price, then we take volume from AMM 168 Then the following trades should be executed: 169 | buyer | price | size | seller | is amm | 170 | party2 | 100 | 50 | party1 | true | 171 | vamm1-id | 99 | 103 | party1 | true | 172 | party2 | 99 | 47 | party1 | true | 173 174 175 @VAMM 176 Scenario: AMM's cannot be submitted/amended/cancelled when a market is terminated 177 178 When the oracles broadcast data signed with "0xCAFECAFE19": 179 | name | value | 180 | trading.terminated | true | 181 Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/MAR22" 182 And the market data for the market "ETH/MAR22" should be: 183 | trading mode | 184 | TRADING_MODE_NO_TRADING | 185 186 Then the parties submit the following AMM: 187 | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | error | 188 | vamm2 | ETH/MAR22 | 100000 | 0.05 | 100 | 95 | 105 | 0.03 | trading not allowed | 189 190 Then the parties amend the following AMM: 191 | party | market id | amount | slippage | base | lower bound | upper bound | upper leverage | error | 192 | vamm1 | ETH/MAR22 | 20000 | 0.15 | 1010 | 910 | 1110 | 0.2 | trading not allowed | 193 194 Then the parties cancel the following AMM: 195 | party | market id | method | error | 196 | party1 | ETH/MAR22 | METHOD_IMMEDIATE | trading not allowed | 197 198 199 @VAMM 200 Scenario: Cannot amend AMM to have only one side if its current position does not support it 201 202 When the parties place the following orders: 203 | party | market id | side | volume | price | resulting trades | type | tif | reference | 204 | party1 | ETH/MAR22 | sell | 1 | 99 | 1 | TYPE_LIMIT | TIF_GTC | | 205 206 207 Then the parties amend the following AMM: 208 | party | market id | amount | slippage | base | upper bound | proposed fee | error | 209 | vamm1 | ETH/MAR22 | 100000 | 0.05 | 100 | 105 | 0.03 | cannot remove lower bound when AMM is long | 210 211 212 When the parties place the following orders: 213 | party | market id | side | volume | price | resulting trades | type | tif | reference | 214 | party1 | ETH/MAR22 | buy | 2 | 200 | 2 | TYPE_LIMIT | TIF_GTC | | 215 216 Then the parties amend the following AMM: 217 | party | market id | amount | slippage | base | lower bound | proposed fee | error | 218 | vamm1 | ETH/MAR22 | 100000 | 0.05 | 100 | 95 | 0.03 | cannot remove upper bound when AMM is short | 219 220 221 @VAMM 222 Scenario: Two AMM's incoming order split pro-rata equally 223 224 When the parties submit the following AMM: 225 | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | 226 | vamm2 | ETH/MAR22 | 100000 | 0.05 | 100 | 95 | 105 | 0.03 | 227 Then the AMM pool status should be: 228 | party | market id | amount | status | base | lower bound | upper bound | 229 | vamm2 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 100 | 95 | 105 | 230 231 And set the following AMM sub account aliases: 232 | party | market id | alias | 233 | vamm2 | ETH/MAR22 | vamm2-id | 234 235 And the market data for the market "ETH/MAR22" should be: 236 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 237 | 100 | TRADING_MODE_CONTINUOUS | 99 | 101 | 206 | 184 | 238 239 240 When the parties place the following orders: 241 | party | market id | side | volume | price | resulting trades | type | tif | reference | 242 | party1 | ETH/MAR22 | sell | 1000 | 10 | 2 | TYPE_LIMIT | TIF_GTC | | 243 Then the following trades should be executed: 244 | buyer | price | size | seller | is amm | 245 | vamm1-id | 97 | 500 | party1 | true | 246 | vamm2-id | 97 | 500 | party1 | true | 247 248 And the market data for the market "ETH/MAR22" should be: 249 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 250 | 100 | TRADING_MODE_CONTINUOUS | 95 | 96 | 70 | 150 | 251 252 @VAMM 253 Scenario: Two AMM's incoming order split pro-rata unequally 254 255 When the parties submit the following AMM: 256 | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | 257 | vamm2 | ETH/MAR22 | 75000 | 0.05 | 100 | 90 | 110 | 0.03 | 258 Then the AMM pool status should be: 259 | party | market id | amount | status | base | lower bound | upper bound | 260 | vamm2 | ETH/MAR22 | 75000 | STATUS_ACTIVE | 100 | 90 | 110 | 261 262 And set the following AMM sub account aliases: 263 | party | market id | alias | 264 | vamm2 | ETH/MAR22 | vamm2-id | 265 266 And the market data for the market "ETH/MAR22" should be: 267 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 268 | 100 | TRADING_MODE_CONTINUOUS | 99 | 101 | 141 | 125 | 269 270 271 When the parties place the following orders: 272 | party | market id | side | volume | price | resulting trades | type | tif | reference | 273 | party1 | ETH/MAR22 | sell | 400 | 10 | 2 | TYPE_LIMIT | TIF_GTC | | 274 Then the following trades should be executed: 275 | buyer | price | size | seller | is amm | 276 | vamm1-id | 98 | 292 | party1 | true | 277 | vamm2-id | 98 | 108 | party1 | true | 278 279 And the market data for the market "ETH/MAR22" should be: 280 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 281 | 100 | TRADING_MODE_CONTINUOUS | 96 | 98 | 184 | 113 | 282 283 284 @VAMM 285 Scenario: Two AMM's incoming order split pro-rata through base price where one side is much wider 286 287 When the parties submit the following AMM: 288 | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | 289 | vamm2 | ETH/MAR22 | 100000 | 0.05 | 100 | 95 | 500 | 0.03 | 290 Then the AMM pool status should be: 291 | party | market id | amount | status | base | lower bound | upper bound | 292 | vamm2 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 100 | 95 | 500 | 293 294 And set the following AMM sub account aliases: 295 | party | market id | alias | 296 | vamm2 | ETH/MAR22 | vamm2-id | 297 298 And the market data for the market "ETH/MAR22" should be: 299 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 300 | 100 | TRADING_MODE_CONTINUOUS | 99 | 101 | 206 | 92 | 301 302 303 When the parties place the following orders: 304 | party | market id | side | volume | price | resulting trades | type | tif | reference | 305 | party1 | ETH/MAR22 | sell | 400 | 10 | 2 | TYPE_LIMIT | TIF_GTC | | 306 Then the following trades should be executed: 307 | buyer | price | size | seller | is amm | 308 | vamm1-id | 99 | 200 | party1 | true | 309 | vamm2-id | 99 | 200 | party1 | true | 310 311 And the market data for the market "ETH/MAR22" should be: 312 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 313 | 100 | TRADING_MODE_CONTINUOUS | 97 | 99 | 232 | 194 | 314 315 316 # now lets swing back across both AMM's base price, AMM2 will have much less volume on that side 317 When the parties place the following orders: 318 | party | market id | side | volume | price | resulting trades | type | tif | reference | 319 | party1 | ETH/MAR22 | buy | 600 | 115 | 4 | TYPE_LIMIT | TIF_GTC | | 320 Then the following trades should be executed: 321 | seller | price | size | buyer | is amm | 322 | vamm1-id | 98 | 200 | party1 | true | 323 | vamm2-id | 98 | 200 | party1 | true | 324 | vamm1-id | 101 | 199 | party1 | true | 325 | vamm2-id | 100 | 1 | party1 | true | 326 327 And the market data for the market "ETH/MAR22" should be: 328 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 329 | 100 | TRADING_MODE_CONTINUOUS | 102 | 104 | 16 | 163 | 330 331 332 333 @VAMM 334 Scenario: 2 AMM's incoming order split pro-rata through, two AMM's are low volume on opposite ends 335 336 When the parties amend the following AMM: 337 | party | market id | amount | slippage | base | lower bound | upper bound | 338 | vamm1 | ETH/MAR22 | 500000 | 0.15 | 2000 | 1995 | 2300 | 339 340 341 When the parties submit the following AMM: 342 | party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | 343 | vamm2 | ETH/MAR22 | 500000 | 0.05 | 2000 | 1700 | 2005 | 0.03 | 344 Then the AMM pool status should be: 345 | party | market id | amount | status | base | lower bound | upper bound | 346 | vamm2 | ETH/MAR22 | 500000 | STATUS_ACTIVE | 2000 | 1700 | 2005 | 347 348 And set the following AMM sub account aliases: 349 | party | market id | alias | 350 | vamm2 | ETH/MAR22 | vamm2-id | 351 352 And the market data for the market "ETH/MAR22" should be: 353 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 354 | 100 | TRADING_MODE_CONTINUOUS | 1999 | 2001 | 25 | 23 | 355 356 357 When the parties place the following orders: 358 | party | market id | side | volume | price | resulting trades | type | tif | reference | 359 | party1 | ETH/MAR22 | sell | 100 | 10 | 2 | TYPE_LIMIT | TIF_GTC | | 360 Then the following trades should be executed: 361 | buyer | price | size | seller | is amm | 362 | vamm1-id | 1998 | 99 | party1 | true | 363 | vamm2-id | 1998 | 1 | party1 | true | 364 365 And the market data for the market "ETH/MAR22" should be: 366 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 367 | 100 | TRADING_MODE_CONTINUOUS | 1995 | 1997 | 30 | 22 | 368 369 370 # now lets swing back across both AMM's base price, AMM2 will have much less volume on that side 371 When the parties place the following orders: 372 | party | market id | side | volume | price | resulting trades | type | tif | reference | 373 | party1 | ETH/MAR22 | buy | 200 | 5000 | 4 | TYPE_LIMIT | TIF_GTC | | 374 Then the following trades should be executed: 375 | seller | price | size | buyer | is amm | 376 | vamm1-id | 1997 | 99 | party1 | true | 377 | vamm2-id | 1998 | 1 | party1 | true | 378 | vamm1-id | 2001 | 1 | party1 | true | 379 | vamm2-id | 2002 | 99 | party1 | true | 380 381 And the market data for the market "ETH/MAR22" should be: 382 | mark price | trading mode | best bid price | best offer price | best bid volume | best offer volume | 383 | 100 | TRADING_MODE_CONTINUOUS | 2004 | 2005 | 5 | 19 |