code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/0053-PERP-039.feature (about) 1 Feature: If a market insurance pool does not have enough funds to cover a funding payment, 2 loss socialisation occurs and the total balances across the network remains constant (0053-PERP-039). 3 4 Background: 5 6 And the perpetual oracles from "0xCAFECAFE1": 7 | name | asset | settlement property | settlement type | schedule property | schedule type | margin funding factor | interest rate | clamp lower bound | clamp upper bound | quote name | settlement decimals | 8 | perp-oracle | USD | perp.ETH.value | TYPE_INTEGER | perp.funding.cue | TYPE_TIMESTAMP | 1.0 | 0.0 | 0.0 | 0.0 | ETH | 18 | 9 And the liquidity sla params named "SLA": 10 | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor | 11 | 1.0 | 0.5 | 1 | 1.0 | 12 13 And the markets: 14 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | position decimal places | market type | sla params | 15 | ETH/DEC19 | ETH | USD | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-none | perp-oracle | 0.25 | 0 | -3 | perp | default-futures | 16 And the initial insurance pool balance is "200" for all the markets 17 And the following network parameters are set: 18 | name | value | 19 | market.auction.minimumDuration | 1 | 20 | limits.markets.maxPeggedOrders | 2 | 21 22 @Perpetual @Liquidation 23 Scenario: 24 Given the following network parameters are set: 25 | name | value | 26 | network.markPriceUpdateMaximumFrequency | 5s | 27 And the parties deposit on asset's general account the following amount: 28 | party | asset | amount | 29 | party1 | USD | 100000000 | 30 | party2 | USD | 100000000 | 31 | party3 | USD | 100000000 | 32 | aux | USD | 4993200 | 33 | aux2 | USD | 100000000 | 34 | lpprov | USD | 100000000 | 35 36 And the cumulated balance for all accounts should be worth "504993400" 37 When the parties submit the following liquidity provision: 38 | id | party | market id | commitment amount | fee | lp type | 39 | lp1 | lpprov | ETH/DEC19 | 10000000 | 0.001 | submission | 40 And the parties place the following pegged iceberg orders: 41 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 42 | lpprov | ETH/DEC19 | 2 | 1 | buy | BID | 50 | 1 | 43 | lpprov | ETH/DEC19 | 2 | 1 | sell | ASK | 50 | 1 | 44 45 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 46 When the parties place the following orders: 47 | party | market id | side | volume | price | resulting trades | type | tif | 48 | aux | ETH/DEC19 | buy | 1 | 49 | 0 | TYPE_LIMIT | TIF_GTC | 49 | aux | ETH/DEC19 | sell | 1 | 5001 | 0 | TYPE_LIMIT | TIF_GTC | 50 | aux2 | ETH/DEC19 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | 51 | aux | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | 52 53 And the market data for the market "ETH/DEC19" should be: 54 | target stake | supplied stake | 55 | 1100000 | 10000000 | 56 Then the opening auction period ends for market "ETH/DEC19" 57 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 58 And the settlement account should have a balance of "0" for the market "ETH/DEC19" 59 And the insurance pool balance should be "200" for the market "ETH/DEC19" 60 61 # back sure we end the block so we're in a new one after opening auction 62 When the network moves ahead "1" blocks 63 Then the oracles broadcast data with block time signed with "0xCAFECAFE1": 64 | name | value | time offset | 65 | perp.ETH.value | 1000000000000000000000 | 0s | 66 67 68 When the parties place the following orders: 69 | party | market id | side | volume | price | resulting trades | type | tif | 70 | party1 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | 71 | party2 | ETH/DEC19 | buy | 1 | 1000 | 1 | TYPE_LIMIT | TIF_GTC | 72 73 And the settlement account should have a balance of "0" for the market "ETH/DEC19" 74 When the parties place the following orders: 75 | party | market id | side | volume | price | resulting trades | type | tif | 76 | party1 | ETH/DEC19 | sell | 1 | 1200 | 0 | TYPE_LIMIT | TIF_GTC | 77 | party3 | ETH/DEC19 | buy | 1 | 1200 | 1 | TYPE_LIMIT | TIF_GTC | 78 79 And the market data for the market "ETH/DEC19" should be: 80 | mark price | trading mode | target stake | supplied stake | open interest | 81 | 1000 | TRADING_MODE_CONTINUOUS | 3300000 | 10000000 | 3 | 82 83 # send in external data to the perpetual market, it should not change anything and a MTM should not happen 84 When the network moves ahead "1" blocks 85 And the mark price should be "1000" for the market "ETH/DEC19" 86 87 When time is updated to "2021-02-10T23:04:12Z" 88 Then system unix time is "1612998252" 89 90 When the oracles broadcast data with block time signed with "0xCAFECAFE1": 91 | name | value | time offset | 92 | perp.ETH.value | 6200000000000000000000 | 0s | 93 | perp.funding.cue | 1612998252 | 0s | 94 95 When the network moves ahead "4" blocks 96 And the mark price should be "1200" for the market "ETH/DEC19" 97 # MTM for mark price 1000 to 1020 98 And the following transfers should happen: 99 | from | to | from account | to account | market id | amount | asset | type | 100 | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 200000 | USD | TRANSFER_TYPE_MTM_LOSS | 101 | aux | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 200000 | USD | TRANSFER_TYPE_MTM_LOSS | 102 | market | aux2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200000 | USD | TRANSFER_TYPE_MTM_WIN | 103 | market | party2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200000 | USD | TRANSFER_TYPE_MTM_WIN | 104 And the cumulated balance for all accounts should be worth "504993400" 105 And the settlement account should have a balance of "0" for the market "ETH/DEC19" 106 And the insurance pool balance should be "200" for the market "ETH/DEC19" 107 When the network moves ahead "1" blocks 108 And the mark price should be "1200" for the market "ETH/DEC19" 109 110 When time is updated to "2021-08-12T11:04:12Z" 111 And system unix time is "1628766252" 112 113 And the oracles broadcast data with block time signed with "0xCAFECAFE1": 114 | name | value | time offset | 115 | perp.funding.cue | 1628766252 | 0s | 116 117 Then the following funding period events should be emitted: 118 | start | end | internal twap | external twap | funding payment | 119 | 1612998252 | 1628766252 | 1200 | 6200 | -5000 | 120 121 # funding payment is 5000000 but party "aux" only has 4793200 122 # check that loss socialisation has happened and that the insurance pool has been cleared to indicate 123 # that there wasn't enough in there to cover the funding payment hence the winning parties received a haircut 124 #And debug funding payment events 125 And the following funding payment events should be emitted: 126 | party | market | amount | loss amount | loss type | 127 | party2 | ETH/DEC19 | 5000000 | -68867 | TYPE_FUNDING_PAYMENT | 128 | party3 | ETH/DEC19 | 5000000 | -68866 | TYPE_FUNDING_PAYMENT | 129 | aux2 | ETH/DEC19 | 5000000 | -68867 | TYPE_FUNDING_PAYMENT | 130 | aux | ETH/DEC19 | -5000000 | 206600 | TYPE_FUNDING_PAYMENT | 131 | party1 | ETH/DEC19 | -10000000 | | | 132 And the following transfers should happen: 133 | from | to | from account | to account | market id | amount | asset | type | 134 | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 1008000 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 135 | party1 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 8992000 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 136 | aux | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 648000 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 137 | aux | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 4145200 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 138 | market | market | ACCOUNT_TYPE_INSURANCE | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 200 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 139 | market | aux2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 4931133 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN | 140 | market | party2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 4931133 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN | 141 | market | party3 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 4931134 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN | 142 143 Then the parties should have the following margin levels: 144 | party | market id | maintenance | 145 | aux | ETH/DEC19 | 0 | 146 147 And the insurance pool balance should be "0" for the market "ETH/DEC19" 148 And the settlement account should have a balance of "0" for the market "ETH/DEC19" 149 150 # Check we still have a constant total amount in all accounts 151 And the cumulated balance for all accounts should be worth "504993400" 152 And the parties should have the following account balances: 153 | party | asset | market id | margin | general | 154 | aux | USD | ETH/DEC19 | 0 | 0 |