Skip to content

Commit

Permalink
fix: address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohill-Patel committed Nov 27, 2023
1 parent f8e85a7 commit f27657a
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Test internal and external twap calculation
Given time is updated to "2020-10-16T00:00:00Z"
And the perpetual oracles from "0xCAFECAFE1":
| 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 |
| perp-oracle | USD | perp.ETH.value | TYPE_INTEGER | perp.funding.cue | TYPE_TIMESTAMP | 0.5 | 0.00 | 0.0 | 0.0 | ETH | 1 |
| perp-oracle | USD | perp.ETH.value | TYPE_INTEGER | perp.funding.cue | TYPE_TIMESTAMP | 0.5 | 0.00 | 0.0 | 0.0 | ETH | 18 |
And the liquidity sla params named "SLA":
| price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
| 100.0 | 0.5 | 1 | 1.0 |
Expand Down Expand Up @@ -60,9 +60,9 @@ Feature: Test internal and external twap calculation
# 1602806400 + 120s = 1602807000
# funding period is ended with perp.funding.cue
And the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.ETH.value | 110 | -1s |
| perp.funding.cue | 1602807000 | 0s |
| name | value | time offset |
| perp.ETH.value | 11000000000000000000 | -1s |
| perp.funding.cue | 1602807000 | 0s |
And the mark price should be "10" for the market "ETH/DEC19"

# 1 min in to the next funding period
Expand All @@ -72,33 +72,33 @@ Feature: Test internal and external twap calculation
| party1 | ETH/DEC19 | buy | 1 | 11 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | sell | 1 | 11 | 1 | TYPE_LIMIT | TIF_GTC |
Then the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.ETH.value | 90 | -1s |
| name | value | time offset |
| perp.ETH.value | 9000000000000000000 | -1s |

# 3 min in to the next funding period
Given time is updated to "2020-10-16T00:13:00Z"
And the mark price should be "11" for the market "ETH/DEC19"
When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | sell | 1 | 10 | 1 | TYPE_LIMIT | TIF_GTC |
| party1 | ETH/DEC19 | buy | 1 | 11 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | sell | 1 | 11 | 1 | TYPE_LIMIT | TIF_GTC |
Then the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.ETH.value | 100 | -1s |
| name | value | time offset |
| perp.ETH.value | 10000000000000000000 | -1s |

# 5 min in to the next funding period market moves into auction
Given time is updated to "2020-10-16T00:15:00Z"
And the mark price should be "10" for the market "ETH/DEC19"
And the mark price should be "11" for the market "ETH/DEC19"
# this spot price is not counted in external twap calclation because it was broadcast during auction
# if it did then the External spot price would be pushed to 11.625 or 11 since field type is int
# similarly the mark price woul dbe pushed to 12.125
When the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.ETH.value | 120 | -1s |
| name | value | time offset |
| perp.ETH.value | 30000000000000000000 | -1s |
And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif | reference |
| aux2 | ETH/DEC19 | buy | 1 | 15 | 0 | TYPE_LIMIT | TIF_GTC | trigger-auction2 |
| aux | ETH/DEC19 | sell | 1 | 15 | 0 | TYPE_LIMIT | TIF_GTC | trigger-auction1 |
And the mark price should be "10" for the market "ETH/DEC19"
Then the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC19"

### 6 mins in Now we cancel the aux2 order, its served its purpose
Expand All @@ -108,45 +108,46 @@ Feature: Test internal and external twap calculation
| aux2 | trigger-auction2 |
When time is updated to "2020-10-16T00:16:00Z"
Then the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.ETH.value | 110 | -1s |
| name | value | time offset |
| perp.ETH.value | 11000000000000000000 | -1s |
And the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC19"

# 7 mins in, the auction period will end
Given time is updated to "2020-10-16T00:17:01Z"
When the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
Then the parties place the following orders:
Then the markets are updated:
| id | price monitoring | linear slippage factor | quadratic slippage factor |
| ETH/DEC19 | default-none | 1e6 | 1e6 |
And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | ETH/DEC19 | buy | 10 | 9 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | sell | 10 | 9 | 1 | TYPE_LIMIT | TIF_GTC |

# 8 mins in, the auction period will end
Given time is updated to "2020-10-16T00:18:00Z"
When the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
And the markets are updated:
| id | price monitoring | linear slippage factor | quadratic slippage factor |
| ETH/DEC19 | default-none | 1e6 | 1e6 |
Then the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | ETH/DEC19 | buy | 1 | 8 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | sell | 1 | 8 | 1 | TYPE_LIMIT | TIF_GTC |
And the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.ETH.value | 80 | -1s |
| name | value | time offset |
| perp.ETH.value | 8000000000000000000 | -1s |

# 9 mins in, the auction period will end
Given time is updated to "2020-10-16T00:19:00Z"
Then the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.ETH.value | 140 | -1s |
| name | value | time offset |
| perp.ETH.value | 14000000000000000000 | -1s |

# 10 mins in, the auction period will end
Given time is updated to "2020-10-16T00:20:00Z"
When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | ETH/DEC19 | buy | 1 | 30 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | sell | 1 | 30 | 1 | TYPE_LIMIT | TIF_GTC |
# in theory internal TWAP = 9.625 external TWAP = 10.25, if the auction period is excluded
# in theory internal TWAP = 9.625 external TWAP = 10.25
# if the auction period is included then the internal TWAP = 10.1 and external TWAP = 11.2
# but these are type int so the decimal is truncated
Then the product data for the market "ETH/DEC19" should be:
| internal twap | external twap |
Expand Down

0 comments on commit f27657a

Please sign in to comment.