code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/Funding-treasury.feature (about) 1 Feature: check the insurance pool getting shared equally between all markets with the same settlement asset + the on-chain treasury for the asset. 2 3 Background: 4 5 Given the log normal risk model named "lognormal-risk-model-fish": 6 | risk aversion | tau | mu | r | sigma | 7 | 0.001 | 0.01 | 0 | 0.0 | 1.2 | 8 #calculated risk factor long: 0.336895684; risk factor short: 0.4878731 9 10 And the price monitoring named "price-monitoring-1": 11 | horizon | probability | auction extension | 12 | 1 | 0.99999999 | 300 | 13 14 And the margin calculator named "margin-calculator-1": 15 | search factor | initial factor | release factor | 16 | 1.2 | 1.5 | 2 | 17 18 And the oracle spec for settlement data filtering data from "0xCAFECAFE19" named "ethDec19Oracle": 19 | property | type | binding | decimals | 20 | prices.ETH.value | TYPE_INTEGER | settlement data | 0 | 21 22 And the oracle spec for trading termination filtering data from "0xCAFECAFE19" named "ethDec19Oracle": 23 | property | type | binding | 24 | trading.terminated | TYPE_BOOLEAN | trading termination | 25 26 And the oracle spec for settlement data filtering data from "0xCAFECAFE20" named "ethDec20Oracle": 27 | property | type | binding | decimals | 28 | prices.ETH.value | TYPE_INTEGER | settlement data | 0 | 29 30 And the oracle spec for trading termination filtering data from "0xCAFECAFE20" named "ethDec20Oracle": 31 | property | type | binding | 32 | trading.terminated | TYPE_BOOLEAN | trading termination | 33 34 And the oracle spec for settlement data filtering data from "0xCAFECAFE21" named "ethDec21Oracle": 35 | property | type | binding | 36 | prices.ETH.value | TYPE_INTEGER | settlement data | 37 38 And the oracle spec for trading termination filtering data from "0xCAFECAFE21" named "ethDec21Oracle": 39 | property | type | binding | 40 | trading.terminated | TYPE_BOOLEAN | trading termination | 41 42 43 And the markets: 44 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 45 | ETH/DEC19 | ETH | USD | lognormal-risk-model-fish | margin-calculator-1 | 1 | default-none | default-none | ethDec19Oracle | 0.74667 | 0 | default-futures | 46 | ETH/DEC20 | ETH | USD | lognormal-risk-model-fish | margin-calculator-1 | 1 | default-none | default-none | ethDec20Oracle | 0.25 | 0 | default-futures | 47 | ETH/DEC21 | ETH | USD | lognormal-risk-model-fish | margin-calculator-1 | 1 | default-none | default-none | ethDec21Oracle | 0.25 | 0 | default-futures | 48 49 50 And the following network parameters are set: 51 | name | value | 52 | market.auction.minimumDuration | 1 | 53 | network.markPriceUpdateMaximumFrequency | 0s | 54 | market.liquidity.successorLaunchWindowLength | 1s | 55 | limits.markets.maxPeggedOrders | 4 | 56 57 Scenario: using lognormal risk model, set "designatedLooser" closeout while the position of "designatedLooser" is not fully covered by orders on the order book; and check the funding of treasury. 0012-POSR-002, 0012-POSR-005, 0013-ACCT-001 58 59 # setup accounts 60 Given the parties deposit on asset's general account the following amount: 61 | party | asset | amount | 62 | sellSideProvider | USD | 1000000000000 | 63 | buySideProvider | USD | 1000000000000 | 64 | designatedLoser | USD | 21981 | 65 | aux | USD | 1000000000000 | 66 | aux2 | USD | 1000000000000 | 67 | lpprov | USD | 1000000000000 | 68 69 Then the parties submit the following liquidity provision: 70 | id | party | market id | commitment amount | fee | lp type | 71 | lp1 | lpprov | ETH/DEC19 | 9000 | 0.1 | submission | 72 | lp2 | lpprov | ETH/DEC20 | 9000 | 0.1 | submission | 73 And the parties place the following pegged iceberg orders: 74 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 75 | lpprov | ETH/DEC19 | 225 | 18 | buy | BID | 225 | 100 | 76 | lpprov | ETH/DEC19 | 36 | 18 | sell | ASK | 36 | 100 | 77 And the parties place the following pegged iceberg orders: 78 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 79 | lpprov | ETH/DEC20 | 225 | 18 | buy | BID | 225 | 100 | 80 | lpprov | ETH/DEC20 | 36 | 18 | sell | ASK | 36 | 100 | 81 82 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 83 Then the parties place the following orders: 84 | party | market id | side | volume | price | resulting trades | type | tif | reference | 85 | aux | ETH/DEC19 | buy | 10 | 1 | 0 | TYPE_LIMIT | TIF_GTC | aux-1-19 | 86 | aux | ETH/DEC19 | sell | 10 | 2000 | 0 | TYPE_LIMIT | TIF_GTC | | 87 | aux | ETH/DEC19 | buy | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | | 88 | aux2 | ETH/DEC19 | sell | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | | 89 Then the parties place the following orders: 90 | party | market id | side | volume | price | resulting trades | type | tif | 91 | aux | ETH/DEC20 | buy | 10 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 92 | aux | ETH/DEC20 | sell | 10 | 2000 | 0 | TYPE_LIMIT | TIF_GTC | 93 | aux | ETH/DEC20 | buy | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 94 | aux2 | ETH/DEC20 | sell | 1 | 150 | 0 | TYPE_LIMIT | TIF_GTC | 95 Then the opening auction period ends for market "ETH/DEC19" 96 And the mark price should be "150" for the market "ETH/DEC19" 97 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 98 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 99 100 # insurance pool generation - setup orderbook 101 When the parties place the following orders with ticks: 102 | party | market id | side | volume | price | resulting trades | type | tif | reference | 103 | sellSideProvider | ETH/DEC19 | sell | 290 | 150 | 0 | TYPE_LIMIT | TIF_GTC | sell-provider-1 | 104 | buySideProvider | ETH/DEC19 | buy | 1 | 140 | 0 | TYPE_LIMIT | TIF_GTC | buy-provider-1 | 105 106 And the market data for the market "ETH/DEC19" should be: 107 | mark price | trading mode | target stake | supplied stake | open interest | 108 | 150 | TRADING_MODE_CONTINUOUS | 731 | 9000 | 1 | 109 #target_stake = mark_price x max_oi x target_stake_scaling_factor x rf=150*10*1*0.4878731=731 110 111 Then the order book should have the following volumes for market "ETH/DEC19": 112 | side | volume | price | 113 | buy | 10 | 1 | 114 | sell | 10 | 2000 | 115 116 # insurance pool generation - trade 117 When the parties place the following orders with ticks: 118 | party | market id | side | volume | price | resulting trades | type | tif | reference | 119 | designatedLoser | ETH/DEC19 | buy | 290 | 150 | 1 | TYPE_LIMIT | TIF_GTC | ref-1 | 120 121 Then the parties should have the following account balances: 122 | party | asset | market id | margin | general | 123 | designatedLoser | USD | ETH/DEC19 | 0 | 0 | 124 125 And the parties should have the following margin levels: 126 | party | market id | maintenance | search | initial | release | 127 | designatedLoser | ETH/DEC19 | 0 | 0 | 0 | 0 | 128 129 And the order book should have the following volumes for market "ETH/DEC19": 130 | side | price | volume | 131 | buy | 1 | 0 | 132 | buy | 140 | 0 | 133 134 When the parties place the following orders with ticks: 135 | party | market id | side | volume | price | resulting trades | type | tif | reference | 136 | buySideProvider | ETH/DEC19 | buy | 290 | 120 | 0 | TYPE_LIMIT | TIF_GTC | buy-provider-2 | 137 138 # insurance pool generation - set new mark price (and trigger closeout) 139 #When the parties place the following orders with ticks: 140 When the parties place the following orders with ticks: 141 | party | market id | side | volume | price | resulting trades | type | tif | reference | 142 | sellSideProvider | ETH/DEC19 | sell | 1 | 140 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 143 | buySideProvider | ETH/DEC19 | buy | 1 | 140 | 1 | TYPE_LIMIT | TIF_GTC | ref-2 | 144 And the network moves ahead "1" blocks 145 146 Then debug trades 147 Then the following trades should be executed: 148 | buyer | price | size | seller | 149 | buySideProvider | 140 | 1 | sellSideProvider | 150 | network | 150 | 290 | designatedLoser | 151 | buySideProvider | 140 | 1 | network | 152 | lpprov | 40 | 225 | network | 153 | aux | 1 | 10 | network | 154 | buySideProvider | 120 | 54 | network | 155 156 Then the following network trades should be executed: 157 | party | aggressor side | volume | 158 | buySideProvider | buy | 1 | 159 | buySideProvider | sell | 1 | 160 | lpprov | sell | 225 | 161 | aux | sell | 10 | 162 | designatedLoser | buy | 290 | 163 164 # check margin levels 165 Then the parties should have the following margin levels: 166 | party | market id | maintenance | search | initial | release | 167 | designatedLoser | ETH/DEC19 | 0 | 0 | 0 | 0 | 168 # checking margins 169 Then the parties should have the following account balances: 170 | party | asset | market id | margin | general | 171 | designatedLoser | USD | ETH/DEC19 | 0 | 0 | 172 173 174 # then we make sure the insurance pool collected the funds (however they get later spent on MTM payment to closeout-facilitating party) 175 Then the following transfers should happen: 176 | from | to | from account | to account | market id | amount | asset | 177 | designatedLoser | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER | ETH/DEC19 | 0 | USD | 178 | designatedLoser | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC19 | 4350 | USD | 179 | designatedLoser | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC19 | 0 | USD | 180 | market | buySideProvider | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL | ETH/DEC19 | 0 | USD | 181 | designatedLoser | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_INSURANCE | ETH/DEC19 | 17631 | USD | 182 | market | market | ACCOUNT_TYPE_INSURANCE | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 16716 | USD | 183 | market | buySideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 8 | USD | 184 | market | buySideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 0 | USD | 185 | market | buySideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 8 | USD | 186 | market | buySideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 0 | USD | 187 188 And the insurance pool balance should be "0" for the market "ETH/DEC19" 189 190 When the parties place the following orders with ticks: 191 | party | market id | side | volume | price | resulting trades | type | tif | reference | 192 | aux2 | ETH/DEC19 | buy | 1 | 120 | 0 | TYPE_LIMIT | TIF_GTC | ref-2 | 193 | aux | ETH/DEC19 | sell | 1 | 120 | 1 | TYPE_LIMIT | TIF_GTC | ref-1 | 194 195 Then the market data for the market "ETH/DEC19" should be: 196 | mark price | trading mode | target stake | supplied stake | open interest | 197 | 120 | TRADING_MODE_CONTINUOUS | 170949 | 9000 | 292 | 198 199 And the insurance pool balance should be "0" for the market "ETH/DEC19" 200 201 Then the following transfers should happen: 202 | from | to | from account | to account | market id | amount | asset | 203 | buySideProvider | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 1120 | USD | 204 | market | sellSideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 5820 | USD | 205 And the insurance pool balance should be "0" for the market "ETH/DEC19" 206 When the oracles broadcast data signed with "0xCAFECAFE19": 207 | name | value | 208 | trading.terminated | true | 209 And time is updated to "2020-01-01T01:01:01Z" 210 211 Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC19" 212 213 And the orders should have the following status: 214 | party | reference | status | 215 | aux | aux-1-19 | STATUS_FILLED | 216 Then the oracles broadcast data signed with "0xCAFECAFE19": 217 | name | value | 218 | prices.ETH.value | 80 | 219 220 # distribute insurance pool for DEC19 221 When the network moves ahead "3" blocks 222 Then the global insurance pool balance should be "0" for the asset "USD" 223 And the insurance pool balance should be "0" for the market "ETH/DEC19" 224 And the insurance pool balance should be "0" for the market "ETH/DEC20" 225 And the insurance pool balance should be "0" for the market "ETH/DEC21" 226 227 When the oracles broadcast data signed with "0xCAFECAFE20": 228 | name | value | 229 | trading.terminated | true | 230 #And time is updated to "2020-01-01T01:01:01Z" 231 Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC20" 232 Then the oracles broadcast data signed with "0xCAFECAFE20": 233 | name | value | 234 | prices.ETH.value | 80 | 235 236 And the network moves ahead "3" blocks 237 # When a market ETH/DEC20 is closed, the insurance pool account has its outstanding funds transferred to the [network treasury] 238 And the global insurance pool balance should be "0" for the asset "USD" 239 And the insurance pool balance should be "0" for the market "ETH/DEC19" 240 And the insurance pool balance should be "0" for the market "ETH/DEC20" 241 And the insurance pool balance should be "0" for the market "ETH/DEC21" 242 243 Then the parties should have the following profit and loss: 244 | party | volume | unrealised pnl | realised pnl | 245 | sellSideProvider | -291 | 0 | 20360 | 246 | buySideProvider | 57 | 0 | -3942 | 247 | designatedLoser | 0 | 0 | -17631 | 248 249 Then the parties should have the following account balances: 250 | party | asset | market id | margin | general | 251 | buySideProvider | USD | ETH/DEC19 | 0 | 999999996044 | 252 | sellSideProvider | USD | ETH/DEC19 | 0 | 1000000020360 | 253 | designatedLoser | USD | ETH/DEC19 | 0 | 0 | 254 | aux | USD | ETH/DEC19 | 0 | 1000000000136 | 255 | aux2 | USD | ETH/DEC19 | 0 | 1000000000140 | 256 | lpprov | USD | ETH/DEC19 | 0 | 1000000005301 |