code.vegaprotocol.io/vega@v0.79.0/core/integration/features/liquidity-provision/margin-release-cancel.feature (about) 1 Feature: Replicate unexpected margin issues - no mid price pegs 2 3 Background: 4 Given the following assets are registered: 5 | id | decimal places | 6 | DAI | 5 | 7 Given the liquidity monitoring parameters: 8 | name | triggering ratio | time window | scaling factor | 9 | lqm-params | 1.0 | 20s | 10.0 | 10 And the log normal risk model named "dai-lognormal-risk": 11 | risk aversion | tau | mu | r | sigma | 12 | 0.00001 | 0.000114077 | 0 | 0 | 0.41 | 13 And the markets: 14 | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | decimal places | linear slippage factor | quadratic slippage factor | sla params | 15 | DAI/DEC22 | DAI | DAI | lqm-params | dai-lognormal-risk | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 5 | 0.5 | 0 | default-futures | 16 And the following network parameters are set: 17 | name | value | 18 | market.auction.minimumDuration | 1 | 19 | network.markPriceUpdateMaximumFrequency | 0s | 20 | limits.markets.maxPeggedOrders | 6 | 21 | validators.epoch.length | 1s | 22 | market.liquidity.earlyExitPenalty | 0 | 23 | market.liquidity.bondPenaltyParameter | 0 | 24 And the average block duration is "1" 25 26 @LPRelease 27 Scenario: Mid price works as expected 28 Given the parties deposit on asset's general account the following amount: 29 | party | asset | amount | 30 | party1 | DAI | 110000000000 | 31 | party2 | DAI | 110000000000 | 32 | party3 | DAI | 110000000000 | 33 | party4 | DAI | 110000000000 | 34 35 And the parties submit the following liquidity provision: 36 | id | party | market id | commitment amount | fee | reference | lp type | 37 | lp1 | party1 | DAI/DEC22 | 20000000000 | 0.01 | lp-1 | submission | 38 39 And the parties place the following pegged iceberg orders: 40 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 41 | party1 | DAI/DEC22 | 5 | 5 | buy | MID | 15 | 10 | 42 | party1 | DAI/DEC22 | 5 | 5 | sell | MID | 15 | 10 | 43 44 When the parties place the following orders: 45 | party | market id | side | volume | price | resulting trades | type | tif | reference | 46 | party2 | DAI/DEC22 | buy | 1 | 800000000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 47 | party2 | DAI/DEC22 | buy | 1 | 3500000000 | 0 | TYPE_LIMIT | TIF_GTC | party2-2 | 48 | party3 | DAI/DEC22 | sell | 1 | 3500000000 | 0 | TYPE_LIMIT | TIF_GTC | party3-1 | 49 | party3 | DAI/DEC22 | sell | 1 | 8200000000 | 0 | TYPE_LIMIT | TIF_GTC | party3-2 | 50 51 And the opening auction period ends for market "DAI/DEC22" 52 Then the following trades should be executed: 53 | buyer | price | size | seller | 54 | party2 | 3500000000 | 1 | party3 | 55 And the order book should have the following volumes for market "DAI/DEC22": 56 | side | price | volume | 57 | sell | 8200000000 | 1 | 58 | sell | 4500000010 | 5 | 59 | buy | 4499999990 | 5 | 60 | buy | 800000000 | 1 | 61 62 When the parties submit the following liquidity provision: 63 | id | party | market id | commitment amount | fee | reference | lp type | 64 | lp2 | party4 | DAI/DEC22 | 10000000000 | 0.01 | lp-2 | submission | 65 66 Then the liquidity provisions should have the following states: 67 | id | party | market | commitment amount | status | 68 | lp2 | party4 | DAI/DEC22 | 10000000000 | STATUS_PENDING | 69 70 And the parties place the following pegged iceberg orders: 71 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 72 | party4 | DAI/DEC22 | 13 | 1 | buy | BID | 6 | 12 | 73 | party4 | DAI/DEC22 | 13 | 1 | sell | ASK | 6 | 12 | 74 And the parties should have the following account balances: 75 | party | asset | market id | margin | general | bond | 76 | party4 | DAI | DAI/DEC22 | 498883383 | 99501116617 | 10000000000 | 77 And the order book should have the following volumes for market "DAI/DEC22": 78 | side | price | volume | 79 | sell | 8200000012 | 6 | 80 | sell | 8200000000 | 1 | 81 | sell | 4500000010 | 5 | 82 | buy | 4499999990 | 5 | 83 | buy | 800000000 | 1 | 84 | buy | 799999988 | 6 | 85 86 When the network moves ahead "3" blocks 87 And the parties should have the following account balances: 88 | party | asset | market id | margin | general | bond | 89 | party4 | DAI | DAI/DEC22 | 498883383 | 99501116617 | 10000000000 | 90 Then the liquidity provisions should have the following states: 91 | id | party | market | commitment amount | status | 92 | lp2 | party4 | DAI/DEC22 | 10000000000 | STATUS_ACTIVE | 93 94 Then the market data for the market "DAI/DEC22" should be: 95 | mark price | trading mode | auction trigger | target stake | supplied stake | open interest | 96 | 3500000000 | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 692650000 | 30000000000 | 1 | 97 98 When the network moves ahead "3" blocks 99 # Try to amend first 100 Then the parties submit the following liquidity provision: 101 | id | party | market id | commitment amount | fee | reference | lp type | 102 | lp2 | party4 | DAI/DEC22 | 1000000000 | 0.01 | lp-2 | amendment | 103 104 When the network moves ahead "3" blocks 105 Then the liquidity provisions should have the following states: 106 | id | party | market | commitment amount | status | 107 | lp2 | party4 | DAI/DEC22 | 1000000000 | STATUS_ACTIVE | 108 109 # LP cancel 110 When party "party4" cancels their liquidity provision for market "DAI/DEC22" 111 Then the network moves ahead "10" blocks 112 113 And the order book should have the following volumes for market "DAI/DEC22": 114 | side | price | volume | 115 | sell | 8200000000 | 1 | 116 | sell | 4500000010 | 5 | 117 | buy | 4499999990 | 5 | 118 | buy | 800000000 | 1 | 119 120 When the network moves ahead "3" blocks 121 Then the parties should have the following account balances: 122 | party | asset | market id | margin | general | bond | 123 | party4 | DAI | DAI/DEC22 | 498883383 | 109501116617 | 0 | 124 125 @LPAmendVersion 126 Scenario: Amend an LP before cancel, check the version events 127 Given the parties deposit on asset's general account the following amount: 128 | party | asset | amount | 129 | party1 | DAI | 110000000000 | 130 | party2 | DAI | 110000000000 | 131 | party3 | DAI | 110000000000 | 132 | party4 | DAI | 110000000000 | 133 134 And the parties submit the following liquidity provision: 135 | id | party | market id | commitment amount | fee | reference | lp type | 136 | lp1 | party1 | DAI/DEC22 | 20000000000 | 0.01 | lp-1 | submission | 137 | lp1 | party1 | DAI/DEC22 | 20000000000 | 0.01 | lp-1 | submission | 138 And the parties place the following pegged iceberg orders: 139 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 140 | party1 | DAI/DEC22 | 2 | 1 | buy | MID | 1 | 10 | 141 | party1 | DAI/DEC22 | 2 | 1 | sell | MID | 1 | 10 | 142 143 When the parties place the following orders: 144 | party | market id | side | volume | price | resulting trades | type | tif | reference | 145 | party2 | DAI/DEC22 | buy | 1 | 800000000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 146 | party2 | DAI/DEC22 | buy | 1 | 3500000000 | 0 | TYPE_LIMIT | TIF_GTC | party2-2 | 147 | party3 | DAI/DEC22 | sell | 1 | 3500000000 | 0 | TYPE_LIMIT | TIF_GTC | party3-1 | 148 | party3 | DAI/DEC22 | sell | 1 | 8200000000 | 0 | TYPE_LIMIT | TIF_GTC | party3-2 | 149 150 And the opening auction period ends for market "DAI/DEC22" 151 Then the following trades should be executed: 152 | buyer | price | size | seller | 153 | party2 | 3500000000 | 1 | party3 | 154 And the mark price should be "3500000000" for the market "DAI/DEC22" 155 And the order book should have the following volumes for market "DAI/DEC22": 156 | side | price | volume | 157 | sell | 8200000000 | 1 | 158 | sell | 4500000010 | 1 | 159 | buy | 4499999990 | 1 | 160 | buy | 800000000 | 1 | 161 162 When the parties submit the following liquidity provision: 163 | id | party | market id | commitment amount | fee | reference | lp type | 164 | lp2 | party4 | DAI/DEC22 | 10000000000 | 0.01 | lp-2 | submission | 165 | lp2 | party4 | DAI/DEC22 | 10000000000 | 0.01 | lp-2 | submission | 166 And the parties place the following pegged iceberg orders: 167 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 168 | party4 | DAI/DEC22 | 2 | 1 | buy | BID | 1 | 12 | 169 | party4 | DAI/DEC22 | 2 | 1 | sell | ASK | 1 | 12 | 170 Then the parties should have the following account balances: 171 | party | asset | market id | margin | general | bond | 172 | party4 | DAI | DAI/DEC22 | 83147230 | 99916852770 | 10000000000 | 173 And the order book should have the following volumes for market "DAI/DEC22": 174 | side | price | volume | 175 | sell | 8200000012 | 1 | 176 | sell | 8200000000 | 1 | 177 | sell | 4500000010 | 1 | 178 | buy | 4499999990 | 1 | 179 | buy | 800000000 | 1 | 180 | buy | 799999988 | 1 | 181 182 # Amending the LP should result in LP versions being different 183 When the parties submit the following liquidity provision: 184 | id | party | market id | commitment amount | fee | reference | lp type | 185 | lp2 | party4 | DAI/DEC22 | 10000000010 | 0.01 | lp-2 | amendment | 186 | lp2 | party4 | DAI/DEC22 | 10000000010 | 0.01 | lp-2 | amendment | 187 And the parties place the following pegged iceberg orders: 188 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 189 | party4 | DAI/DEC22 | 2 | 1 | buy | BID | 1 | 12 | 190 | party4 | DAI/DEC22 | 2 | 1 | sell | ASK | 1 | 12 | 191 Then the parties should have the following account balances: 192 | party | asset | market id | margin | general | bond | 193 | party4 | DAI | DAI/DEC22 | 166294461 | 99833705529 | 10000000010 | 194 And the following LP events should be emitted: 195 | party | id | version | commitment amount | final | 196 | party4 | lp2 | 1 | 10000000000 | false | 197 | party4 | lp2 | 2 | 10000000010 | true | 198 199 # LP cancel -> orders are gone from the book + margin balance is released 200 When party "party4" cancels their liquidity provision for market "DAI/DEC22" 201 Then the order book should have the following volumes for market "DAI/DEC22": 202 | side | price | volume | 203 | sell | 8200000000 | 1 | 204 | sell | 4500000010 | 1 | 205 | buy | 4499999990 | 1 | 206 | buy | 800000000 | 1 | 207 And the parties should have the following account balances: 208 | party | asset | market id | margin | general | bond | 209 | party4 | DAI | DAI/DEC22 | 166294461 | 109833705539 | 0 |