code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/0053-PERP-027_twap_calculation.feature (about) 1 Feature: Test internal and external twap calculation 2 3 Background: 4 # epoch time is 1602806400 5 Given time is updated to "2020-10-16T00:00:00Z" 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 | 0.5 | 0.00 | 0.0 | 0.0 | ETH | 1 | 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 17 And the following network parameters are set: 18 | name | value | 19 | market.auction.minimumDuration | 1 | 20 | limits.markets.maxPeggedOrders | 2 | 21 And the following network parameters are set: 22 | name | value | 23 | network.markPriceUpdateMaximumFrequency | 0s | 24 And the average block duration is "1" 25 26 @Perpetual @twap 27 Scenario: 0053-PERP-027 Internal and External TWAP calculation 28 Given the following network parameters are set: 29 | name | value | 30 | network.markPriceUpdateMaximumFrequency | 120s | 31 And the parties deposit on asset's general account the following amount: 32 | party | asset | amount | 33 | party1 | USD | 10000000 | 34 | party2 | USD | 10000000 | 35 | party3 | USD | 10000000 | 36 | aux | USD | 100000000 | 37 | aux2 | USD | 100000000 | 38 | lpprov | USD | 100000000 | 39 40 When the parties submit the following liquidity provision: 41 | id | party | market id | commitment amount | fee | lp type | 42 | lp1 | lpprov | ETH/DEC19 | 100000 | 0.001 | submission | 43 44 # move market to continuous 45 And the parties place the following orders: 46 | party | market id | side | volume | price | resulting trades | type | tif | 47 | lpprov | ETH/DEC19 | buy | 1000 | 5 | 0 | TYPE_LIMIT | TIF_GTC | 48 | aux | ETH/DEC19 | buy | 1 | 5 | 0 | TYPE_LIMIT | TIF_GTC | 49 | lpprov | ETH/DEC19 | sell | 1000 | 15 | 0 | TYPE_LIMIT | TIF_GTC | 50 | aux | ETH/DEC19 | sell | 1 | 15 | 0 | TYPE_LIMIT | TIF_GTC | 51 | aux2 | ETH/DEC19 | buy | 1 | 11 | 0 | TYPE_LIMIT | TIF_GTC | 52 | aux | ETH/DEC19 | sell | 1 | 11 | 0 | TYPE_LIMIT | TIF_GTC | 53 54 And the market data for the market "ETH/DEC19" should be: 55 | target stake | supplied stake | 56 | 12100 | 100000 | 57 Then the opening auction period ends for market "ETH/DEC19" 58 59 Given the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 60 When time is updated to "2020-10-16T00:02:00Z" 61 # 1602806400 + 120s = 1602806520 62 # funding period is ended with perp.funding.cue 63 Then the oracles broadcast data with block time signed with "0xCAFECAFE1": 64 | name | value | time offset | 65 | perp.ETH.value | 110 | -1s | 66 | perp.funding.cue | 1602806520 | 0s | 67 68 # 1 min in to the next funding period 69 Given time is updated to "2020-10-16T00:03:00Z" 70 When the parties place the following orders: 71 | party | market id | side | volume | price | resulting trades | type | tif | 72 | party1 | ETH/DEC19 | buy | 1 | 11 | 0 | TYPE_LIMIT | TIF_GTC | 73 | party2 | ETH/DEC19 | sell | 1 | 11 | 1 | TYPE_LIMIT | TIF_GTC | 74 75 And the oracles broadcast data with block time signed with "0xCAFECAFE1": 76 | name | value | time offset | 77 | perp.ETH.value | 90 | -1s | 78 79 # 3 min in to the next funding period 80 Given time is updated to "2020-10-16T00:05:00Z" 81 And the mark price should be "11" for the market "ETH/DEC19" 82 When the parties place the following orders: 83 | party | market id | side | volume | price | resulting trades | type | tif | 84 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | 85 | party2 | ETH/DEC19 | sell | 1 | 10 | 1 | TYPE_LIMIT | TIF_GTC | 86 87 Then the oracles broadcast data with block time signed with "0xCAFECAFE1": 88 | name | value | time offset | 89 | perp.ETH.value | 100 | -1s | 90 91 92 # 5 min in to the next funding period 93 Given time is updated to "2020-10-16T00:07:00Z" 94 And the mark price should be "10" for the market "ETH/DEC19" 95 When the parties place the following orders: 96 | party | market id | side | volume | price | resulting trades | type | tif | 97 | party1 | ETH/DEC19 | buy | 1 | 9 | 0 | TYPE_LIMIT | TIF_GTC | 98 | party2 | ETH/DEC19 | sell | 1 | 9 | 1 | TYPE_LIMIT | TIF_GTC | 99 100 Then the oracles broadcast data with block time signed with "0xCAFECAFE1": 101 | name | value | time offset | 102 | perp.ETH.value | 120 | -1s | 103 104 # 6 min in to the funding period emit spot price 105 Given time is updated to "2020-10-16T00:08:00Z" 106 And the oracles broadcast data with block time signed with "0xCAFECAFE1": 107 | name | value | time offset | 108 | perp.ETH.value | 110 | -1s | 109 110 # 7 mins in to the funding period 111 When time is updated to "2020-10-16T00:09:00Z" 112 113 And the mark price should be "9" for the market "ETH/DEC19" 114 115 And the parties place the following orders: 116 | party | market id | side | volume | price | resulting trades | type | tif | 117 | party1 | ETH/DEC19 | buy | 1 | 8 | 0 | TYPE_LIMIT | TIF_GTC | 118 | party2 | ETH/DEC19 | sell | 1 | 8 | 1 | TYPE_LIMIT | TIF_GTC | 119 120 Then the oracles broadcast data with block time signed with "0xCAFECAFE1": 121 | name | value | time offset | 122 | perp.ETH.value | 80 | -1s | 123 124 # 9 min in to the next funding period 125 Given time is updated to "2020-10-16T00:11:00Z" 126 And the mark price should be "8" for the market "ETH/DEC19" 127 When the parties place the following orders: 128 | party | market id | side | volume | price | resulting trades | type | tif | 129 | party1 | ETH/DEC19 | buy | 1 | 7 | 0 | TYPE_LIMIT | TIF_GTC | 130 | party2 | ETH/DEC19 | sell | 1 | 7 | 1 | TYPE_LIMIT | TIF_GTC | 131 132 Then the oracles broadcast data with block time signed with "0xCAFECAFE1": 133 | name | value | time offset | 134 | perp.ETH.value | 140 | -1s | 135 136 # if the funding period ended here, check the twap 137 Given time is updated to "2020-10-16T00:12:00Z" 138 139 # in theory internal TWAP = 9.3 external TWAP = 10.3 140 # but these are type int so the decimal is truncated 141 Then the product data for the market "ETH/DEC19" should be: 142 | internal twap | external twap | 143 | 10 | 10 |