code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/0019-MCAL_fundingMargin4.feature (about) 1 Feature: Test funding margin for Perps market 2 3 @Perpetual 4 Scenario: (0019-MCAL-027, 0019-MCAL-030 - cross margin, 0019-MCAL-058, 0019-MCAL-054 - isolated margin) check funding margin for Perps market when clumps are -0.05 and 0.05 5 Given the following assets are registered: 6 | id | decimal places | 7 | USD | 3 | 8 And the perpetual oracles from "0xCAFECAFE1": 9 | 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 | 10 | perp-oracle | USD | perp.ETH.value | TYPE_INTEGER | perp.funding.cue | TYPE_TIMESTAMP | 0.5 | 0.05 | -0.05 | 0.05 | ETH | 18 | 11 And the markets: 12 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | decimal places | position decimal places | market type | sla params | 13 | ETH/DEC19 | ETH | USD | default-simple-risk-model-4 | default-margin-calculator | 1 | default-none | default-none | perp-oracle | 0.25 | 0 | 0 | 0 | perp | default-futures | 14 And time is updated to "2024-01-01T00:00:00Z" 15 And the parties deposit on asset's general account the following amount: 16 | party | asset | amount | 17 | party1 | USD | 1000000000 | 18 | party2 | USD | 1000000000 | 19 | party3 | USD | 1000000000 | 20 | party4 | USD | 1000000000 | 21 | aux | USD | 1000000000 | 22 | aux2 | USD | 1000000000 | 23 24 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 25 When the parties place the following orders: 26 | party | market id | side | volume | price | resulting trades | type | tif | 27 | aux | ETH/DEC19 | buy | 1 | 50 | 0 | TYPE_LIMIT | TIF_GTC | 28 | aux2 | ETH/DEC19 | sell | 1 | 5000 | 0 | TYPE_LIMIT | TIF_GTC | 29 | party1 | ETH/DEC19 | sell | 1 | 1500 | 0 | TYPE_LIMIT | TIF_GTC | 30 | party2 | ETH/DEC19 | buy | 1 | 1500 | 0 | TYPE_LIMIT | TIF_GTC | 31 Then the opening auction period ends for market "ETH/DEC19" 32 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 33 34 35 When the parties place the following orders: 36 | party | market id | side | volume | price | resulting trades | type | tif | 37 | party4 | ETH/DEC19 | buy | 1 | 1500 | 0 | TYPE_LIMIT | TIF_GTC | 38 | party3 | ETH/DEC19 | sell | 1 | 1500 | 1 | TYPE_LIMIT | TIF_GTC | 39 And the parties submit update margin mode: 40 | party | market | margin_mode | margin_factor | 41 | party3 | ETH/DEC19 | isolated margin | 0.5 | 42 | party4 | ETH/DEC19 | isolated margin | 0.75 | 43 Then the mark price should be "1500" for the market "ETH/DEC19" 44 And the parties should have the following margin levels: 45 | party | market id | maintenance | margin mode | 46 | party1 | ETH/DEC19 | 525000 | cross margin | 47 | party2 | ETH/DEC19 | 525000 | cross margin | 48 | party3 | ETH/DEC19 | 525000 | isolated margin | 49 | party4 | ETH/DEC19 | 525000 | isolated margin | 50 51 When the oracles broadcast data with block time signed with "0xCAFECAFE1": 52 | name | value | time offset | 53 | perp.ETH.value | 1600000000000000000000 | 0s | 54 And time is updated to "2024-01-01T17:31:03Z" 55 # We need a trade a different price to trigger MTM 56 And the parties place the following orders: 57 | party | market id | side | volume | price | resulting trades | type | tif | 58 | aux | ETH/DEC19 | buy | 1 | 1501 | 0 | TYPE_LIMIT | TIF_GTC | 59 | aux2 | ETH/DEC19 | sell | 1 | 1501 | 1 | TYPE_LIMIT | TIF_GTC | 60 And the network moves ahead "5" blocks 61 # Now trade at desired price and forward time again to trigger another MTM 62 And the parties place the following orders: 63 | party | market id | side | volume | price | resulting trades | type | tif | 64 | aux | ETH/DEC19 | buy | 1 | 1500 | 0 | TYPE_LIMIT | TIF_GTC | 65 | aux2 | ETH/DEC19 | sell | 1 | 1500 | 1 | TYPE_LIMIT | TIF_GTC | 66 And the network moves ahead "5" blocks 67 Then the parties should have the following margin levels: 68 | party | market id | maintenance | margin mode | 69 | party1 | ETH/DEC19 | 535000 | cross margin | 70 | party2 | ETH/DEC19 | 525000 | cross margin | 71 | party3 | ETH/DEC19 | 535000 | isolated margin | 72 | party4 | ETH/DEC19 | 525000 | isolated margin | 73 74 When the system unix time is "1704130273" 75 And the oracles broadcast data with block time signed with "0xCAFECAFE1": 76 | name | value | time offset | 77 | perp.funding.cue | 1704130273 | 0s | 78 Then the following funding period events should be emitted: 79 | start | end | internal twap | external twap | funding payment | funding rate | 80 | 1704067201000000000 | 1704130273000000000 | 1500000 | 1600000 | -20000 | -0.0125 | 81 And the following transfers should happen: 82 | from | to | from account | to account | market id | amount | asset | type | 83 | market | party2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 20000 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN | 84 | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 20000 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS | 85 | market | party4 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 20000 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_WIN | 86 | party3 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 20000 | USD | TRANSFER_TYPE_PERPETUALS_FUNDING_LOSS |