code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/insurance-pools-at-settlement.feature (about) 1 Feature: Test the transfers to and from the insurance pools when markets terminate in various ways 2 Background: 3 Given the average block duration is "1" 4 And the following assets are registered: 5 | id | decimal places | 6 | ETH | 5 | 7 8 # Max pegged orders 2, min auction duration 1s, constant MTM, 5s successor window length 9 And the following network parameters are set: 10 | name | value | 11 | market.auction.minimumDuration | 1 | 12 | market.auction.maximumDuration | 10s | 13 | network.markPriceUpdateMaximumFrequency | 0s | 14 | market.liquidity.successorLaunchWindowLength | 5s | 15 | limits.markets.maxPeggedOrders | 2 | 16 17 And the price monitoring named "price-monitoring-1": 18 | horizon | probability | auction extension | 19 | 1 | 0.99999999 | 300 | 20 And the log normal risk model named "lognormal-risk-model-fish": 21 | risk aversion | tau | mu | r | sigma | 22 | 0.001 | 0.01 | 0 | 0.0 | 1.2 | 23 24 And the margin calculator named "margin-calculator-1": 25 | search factor | initial factor | release factor | 26 | 1.2 | 1.5 | 2 | 27 And the fees configuration named "fees-config-1": 28 | maker fee | infrastructure fee | 29 | 0.005 | 0.02 | 30 31 And the oracle spec for settlement data filtering data from "0xCAFECAFE" named "ethDec19Oracle": 32 | property | type | binding | 33 | prices.ETH.value | TYPE_INTEGER | settlement data | 34 And the oracle spec for trading termination filtering data from "0xCAFECAFE" named "ethDec19Oracle": 35 | property | type | binding | 36 | trading.terminated | TYPE_BOOLEAN | trading termination | 37 38 And the oracle spec for settlement data filtering data from "0xCAFECAFE1" named "ethDec20Oracle": 39 | property | type | binding | 40 | prices.ETH.value | TYPE_INTEGER | settlement data | 41 And the oracle spec for trading termination filtering data from "0xCAFECAFE1" named "ethDec20Oracle": 42 | property | type | binding | 43 | trading.terminated | TYPE_BOOLEAN | trading termination | 44 45 And the oracle spec for settlement data filtering data from "0xCAFECAFE2" named "ethDec21Oracle": 46 | property | type | binding | 47 | prices.ETH.value | TYPE_INTEGER | settlement data | 48 And the oracle spec for trading termination filtering data from "0xCAFECAFE2" named "ethDec21Oracle": 49 | property | type | binding | 50 | trading.terminated | TYPE_BOOLEAN | trading termination | 51 52 # Create 4 markets, all with the same settlement asset, different configs, because we can... 53 And the markets: 54 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 55 | ETH/DEC19 | ETH | ETH | lognormal-risk-model-fish | default-margin-calculator | 1 | default-none | default-none | ethDec19Oracle | 0.25 | 0 | default-futures | 56 | ETH/DEC20 | ETH | ETH | default-log-normal-risk-model | margin-calculator-1 | 1 | default-none | default-none | ethDec20Oracle | 0.25 | 0 | default-futures | 57 | ETH/DEC21 | ETH | ETH | default-simple-risk-model | default-margin-calculator | 1 | fees-config-1 | price-monitoring-1 | ethDec21Oracle | 0.25 | 0 | default-futures | 58 | ETH/DEC22 | ETH | ETH | default-log-normal-risk-model | default-margin-calculator | 1 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.25 | 0 | default-futures | 59 | ETH/DEC23 | ETH | ETH | default-log-normal-risk-model | default-margin-calculator | 1 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.25 | 0 | default-futures | 60 # set their insurance pool to some balance 61 And the initial insurance pool balance is "1000000" for all the markets 62 63 @InsurancePools 64 Scenario: Check insurance pool balances when markets are settled in a variety of ways, at different points in time 65 Given the parties deposit on asset's general account the following amount: 66 | party | asset | amount | 67 | party1 | ETH | 1000000000000 | 68 | party2 | ETH | 1000000000000 | 69 | party3 | ETH | 1000000000000 | 70 | party4 | ETH | 1000000000000 | 71 | party5 | ETH | 1000000000000 | 72 | party6 | ETH | 1000000000000 | 73 | aux1 | ETH | 1000000000000 | 74 | aux2 | ETH | 1000000000000 | 75 | lpprov1 | ETH | 1000000000000 | 76 | lpprov2 | ETH | 1000000000000 | 77 | lpprov3 | ETH | 1000000000000 | 78 | lpprov4 | ETH | 1000000000000 | 79 # Provide liquidity on 19, 20, 21 80 And the parties submit the following liquidity provision: 81 | id | party | market id | commitment amount | fee | lp type | 82 | lp1 | lpprov1 | ETH/DEC19 | 90000000 | 0.1 | submission | 83 | lp1 | lpprov1 | ETH/DEC19 | 90000000 | 0.1 | submission | 84 | lp2 | lpprov2 | ETH/DEC20 | 90000000 | 0.1 | submission | 85 | lp2 | lpprov2 | ETH/DEC20 | 90000000 | 0.1 | submission | 86 | lp3 | lpprov3 | ETH/DEC21 | 90000000 | 0.1 | submission | 87 | lp3 | lpprov3 | ETH/DEC21 | 90000000 | 0.1 | submission | 88 | lp4 | lpprov4 | ETH/DEC22 | 90000000 | 0.1 | submission | 89 | lp4 | lpprov4 | ETH/DEC22 | 90000000 | 0.1 | submission | 90 And the parties place the following pegged iceberg orders: 91 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 92 | lpprov2 | ETH/DEC20 | 2 | 1 | buy | BID | 500 | 10 | 93 | lpprov2 | ETH/DEC20 | 2 | 1 | sell | ASK | 500 | 10 | 94 | lpprov3 | ETH/DEC21 | 2 | 1 | buy | BID | 500 | 10 | 95 | lpprov3 | ETH/DEC21 | 2 | 1 | sell | ASK | 500 | 10 | 96 | lpprov4 | ETH/DEC22 | 2 | 1 | buy | BID | 500 | 10 | 97 | lpprov4 | ETH/DEC22 | 2 | 1 | sell | ASK | 500 | 10 | 98 99 # ETH/DEC19 leaves opening auction 100 When the parties place the following orders: 101 | party | market id | side | volume | price | resulting trades | type | tif | 102 | aux1 | ETH/DEC19 | buy | 10 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 103 | aux1 | ETH/DEC19 | sell | 10 | 2000 | 0 | TYPE_LIMIT | TIF_GTC | 104 | aux1 | ETH/DEC19 | buy | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 105 | aux2 | ETH/DEC19 | sell | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 106 | lpprov1 | ETH/DEC19 | buy | 225 | 40 | 0 | TYPE_LIMIT | TIF_GTC | 107 | lpprov1 | ETH/DEC19 | sell | 36 | 250 | 0 | TYPE_LIMIT | TIF_GTC | 108 And the network moves ahead "2" blocks 109 Then the mark price should be "150" for the market "ETH/DEC19" 110 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 111 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC20" 112 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC21" 113 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC22" 114 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC23" 115 116 ## Now ETH/DEC20 leaves opening auction 117 When the parties place the following orders: 118 | party | market id | side | volume | price | resulting trades | type | tif | 119 | party1 | ETH/DEC20 | buy | 10 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 120 | party1 | ETH/DEC20 | sell | 10 | 2000 | 0 | TYPE_LIMIT | TIF_GTC | 121 | party1 | ETH/DEC20 | buy | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 122 | party2 | ETH/DEC20 | sell | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 123 And the network moves ahead "1" blocks 124 Then the mark price should be "150" for the market "ETH/DEC20" 125 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 126 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 127 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC21" 128 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC22" 129 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC23" 130 131 ## let's have ETH/DEC21 leave opening auction 132 When the parties place the following orders: 133 | party | market id | side | volume | price | resulting trades | type | tif | 134 | party3 | ETH/DEC21 | buy | 10 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 135 | party3 | ETH/DEC21 | sell | 10 | 2000 | 0 | TYPE_LIMIT | TIF_GTC | 136 | party4 | ETH/DEC21 | buy | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 137 | party4 | ETH/DEC21 | sell | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 138 And the network moves ahead "1" blocks 139 Then the mark price should be "150" for the market "ETH/DEC21" 140 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 141 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 142 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 143 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC22" 144 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC23" 145 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 146 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 147 And the insurance pool balance should be "1000000" for the market "ETH/DEC21" 148 And the insurance pool balance should be "1000000" for the market "ETH/DEC22" 149 And the insurance pool balance should be "1000000" for the market "ETH/DEC23" 150 151 ## final market to leave auction is ETH/DEC22 152 When the parties place the following orders: 153 | party | market id | side | volume | price | resulting trades | type | tif | 154 | party5 | ETH/DEC22 | buy | 10 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 155 | party5 | ETH/DEC22 | sell | 10 | 2000 | 0 | TYPE_LIMIT | TIF_GTC | 156 | party6 | ETH/DEC22 | buy | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 157 | party6 | ETH/DEC22 | sell | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 158 And the network moves ahead "1" blocks 159 Then the mark price should be "150" for the market "ETH/DEC22" 160 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 161 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 162 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 163 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC22" 164 And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC23" 165 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 166 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 167 And the insurance pool balance should be "1000000" for the market "ETH/DEC21" 168 And the insurance pool balance should be "1000000" for the market "ETH/DEC22" 169 And the insurance pool balance should be "1000000" for the market "ETH/DEC23" 170 ## Now cancel the first market, before it even left opening auction... 171 # No succession to consider, the insurance pool is instantly distributed 172 When the market states are updated through governance: 173 | market id | state | settlement price | 174 | ETH/DEC23 | MARKET_STATE_UPDATE_TYPE_TERMINATE | 150 | 175 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 176 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 177 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 178 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC22" 179 And the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC23" 180 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 181 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 182 And the insurance pool balance should be "1000000" for the market "ETH/DEC21" 183 And the insurance pool balance should be "1000000" for the market "ETH/DEC22" 184 And the insurance pool balance should be "0" for the market "ETH/DEC23" 185 And the global insurance pool balance should be "1000000" for the asset "ETH" 186 187 # OK, let's terminate a market via governance that is in continuous trading 188 # The successor time window now comes in to play 189 When the market states are updated through governance: 190 | market id | state | settlement price | 191 | ETH/DEC22 | MARKET_STATE_UPDATE_TYPE_TERMINATE | 150 | 192 Then the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC22" 193 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 194 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 195 And the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC22" 196 And the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC23" 197 # insurance pool is not yet distributed 198 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 199 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 200 And the insurance pool balance should be "1000000" for the market "ETH/DEC21" 201 And the insurance pool balance should be "1000000" for the market "ETH/DEC22" 202 And the insurance pool balance should be "0" for the market "ETH/DEC23" 203 And the global insurance pool balance should be "1000000" for the asset "ETH" 204 # pass the successor time window 205 When the network moves ahead "10" blocks 206 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 207 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 208 # these markets no longer exist, so we can ignore them 209 #And the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC22" 210 #And the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC23" 211 ## now we should see the update 212 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 213 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 214 And the insurance pool balance should be "1000000" for the market "ETH/DEC21" 215 ## Nothing in the drained pool, nothing goes to the insurance pool of the old market 216 And the insurance pool balance should be "0" for the market "ETH/DEC22" 217 And the insurance pool balance should be "0" for the market "ETH/DEC23" 218 And the global insurance pool balance should be "2000000" for the asset "ETH" 219 220 ## Now settle a market via the oracle 221 When the oracles broadcast data signed with "0xCAFECAFE2": 222 | name | value | 223 | trading.terminated | true | 224 And the network moves ahead "1" blocks 225 Then the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC21" 226 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 227 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 228 And the insurance pool balance should be "1000000" for the market "ETH/DEC21" 229 ## Nothing in the drained pool, nothing goes to the insurance pool of the old market 230 And the insurance pool balance should be "0" for the market "ETH/DEC22" 231 And the insurance pool balance should be "0" for the market "ETH/DEC23" 232 And the global insurance pool balance should be "2000000" for the asset "ETH" 233 # Moving past the successor window means nothing here, market is not settled 234 When the network moves ahead "10" blocks 235 Then the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC21" 236 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 237 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 238 And the insurance pool balance should be "1000000" for the market "ETH/DEC21" 239 ## Nothing in the drained pool, nothing goes to the insurance pool of the old market 240 And the insurance pool balance should be "0" for the market "ETH/DEC22" 241 And the insurance pool balance should be "0" for the market "ETH/DEC23" 242 And the global insurance pool balance should be "2000000" for the asset "ETH" 243 244 ## Now settle the terminated market 245 When the oracles broadcast data signed with "0xCAFECAFE2": 246 | name | value | 247 | prices.ETH.value | 150 | 248 And the network moves ahead "10" blocks 249 Then the insurance pool balance should be "1000000" for the market "ETH/DEC19" 250 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 251 And the insurance pool balance should be "0" for the market "ETH/DEC21" 252 ## Nothing in the drained pool, nothing goes to the insurance pool of the old market 253 And the insurance pool balance should be "0" for the market "ETH/DEC22" 254 And the insurance pool balance should be "0" for the market "ETH/DEC23" 255 And the global insurance pool balance should be "3000000" for the asset "ETH" 256 257 ## Now terminate both of the other markets 258 When the oracles broadcast data signed with "0xCAFECAFE1": 259 | name | value | 260 | trading.terminated | true | 261 And the oracles broadcast data signed with "0xCAFECAFE": 262 | name | value | 263 | trading.terminated | true | 264 Then the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC20" 265 And the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC19" 266 And the insurance pool balance should be "1000000" for the market "ETH/DEC19" 267 And the insurance pool balance should be "1000000" for the market "ETH/DEC20" 268 And the global insurance pool balance should be "3000000" for the asset "ETH" 269 270 ## Now settle one market, pass the successor window and ensure the insurance pool is divided between the global insurance pool and the terminated market 271 When the oracles broadcast data signed with "0xCAFECAFE1": 272 | name | value | 273 | prices.ETH.value | 150 | 274 And the network moves ahead "10" blocks 275 Then the insurance pool balance should be "1000000" for the market "ETH/DEC19" 276 And the global insurance pool balance should be "4000000" for the asset "ETH" 277 ## the insurance pools from the settled/cancelled markets are all drained 278 And the insurance pool balance should be "0" for the market "ETH/DEC20" 279 And the insurance pool balance should be "0" for the market "ETH/DEC21" 280 And the insurance pool balance should be "0" for the market "ETH/DEC22" 281 And the insurance pool balance should be "0" for the market "ETH/DEC23" 282 283 ## Now settle the last market, and ensure the insurance pool balance is fully transferred to the global pool 284 When the oracles broadcast data signed with "0xCAFECAFE": 285 | name | value | 286 | prices.ETH.value | 150 | 287 And the network moves ahead "10" blocks 288 And the global insurance pool balance should be "5000000" for the asset "ETH" 289 ## the insurance pools from the settled/cancelled markets are all drained 290 Then the insurance pool balance should be "0" for the market "ETH/DEC19" 291 And the insurance pool balance should be "0" for the market "ETH/DEC20" 292 And the insurance pool balance should be "0" for the market "ETH/DEC21" 293 And the insurance pool balance should be "0" for the market "ETH/DEC22" 294 And the insurance pool balance should be "0" for the market "ETH/DEC23"