Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding perp spec copies #1870

Merged
merged 6 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol/0002-STTL-settlement.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The [market lifecycle spec](./0043-MKTL-market_lifecycle.md) provides detail on

## Acceptance Criteria

### The typical "Happy Path" case (<a name="0002-STTL-001" href="#0002-STTL-001">0002-STTL-001</a>)
### The typical "Happy Path" case (<a name="0002-STTL-001" href="#0002-STTL-001">0002-STTL-001</a>,)

- With a market configured to take an oracle termination time and settlement price and put into continuous trading mode. When there are traders with open positions on the market and the termination trigger from oracle is sent so the market is terminated. Send market settlement price and assert that it is no longer possible to trade on this market.

Expand Down
29 changes: 29 additions & 0 deletions protocol/0043-MKTL-market_lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,35 @@ Market state is `suspended`.
The market state is `active`.
1. When a new governance proposal for "closing" the Spot market, then market state is `trading terminated`.

### Lifecycle happy path in Perpetual market(<a name="0043-MKTL-009" href="#0043-MKTL-009">0043-MKTL-009</a>)

1. Market `m1` is proposed with an internal trading terminated oracle set for some time in the future. Price monitoring is configured (e.g. like `2668-price-monitoring.feature`).
Market state is `proposed`.
The LP bond of the party that proposed the market is transferred from general to bond account.
1. Market `m1` is accepted and enters opening auction.
Market state is `pending`.
1. Parties place orders and at least one trade happens in continuous trading mode.
Market state is `active`.
1. Parties place orders so that a [price monitoring auction is triggered](0032-PRIM-price_monitoring.md).
Market state is `suspended`.
1. Price monitoring auction ends and the market is in continuous trading again.
The market state is `active`.
1. Parties cancel orders so that there is no "best static bid" on the order book.
The market enters [liquidity monitoring auction](0035-LIQM-liquidity_monitoring.md).
The market state is `suspended`.
1. A party place bid; this becomes a best static bid.
After the specified time the liquidity auction ends.
The market state is `active`.
1. Make sure that trades happen so that at least two parties have open positions.

1. An oracle event arrives which triggers the perpetual market's interim settlement logic, causing cashflow transfers but the market remains open.
1. Further trades happen, with parties still having different positions to previously. The mark price is `p`.
1. A market state change proposal is created to terminate the market at a given price that is *not* equal to `p`.
When this is approved and enacted the market state is `closed`.
Parties that had open positions see settlement cash-flows happen to settle positions.
Margin account balances are transferred to the general account.
After `market.liquidity.successorLaunchWindowLength` has passed since market settlement, any insurance pool balance is [redistributed](./0015-INSR-market_insurance_pool_collateral.md) to the on-chain treasury for the settlement asset of the market and other insurance pools using the same asset.

### Market never leaves opening auction, trading terminated triggered, market cancelled (<a name="0043-MKTL-003" href="#0043-MKTL-003">0043-MKTL-003</a>)

1. A market is proposed, approved by governance process and enters the opening auction (Pending state).
Expand Down
6 changes: 3 additions & 3 deletions protocol/0051-PROD-product.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ APIS should be available to:

Settlement assets:

- A product of any type cannot be created without specifying at least one settlement asset (<a name="0051-PROD-001" href="#0051-PROD-001">0051-PROD-001</a>) for product spot: (<a name="0051-PROD-004" href="#0051-PROD-004">0051-PROD-004</a>)
- The settlement asset or assets must exist at the time when the product is created (<a name="0051-PROD-002" href="#0051-PROD-002">0051-PROD-002</a>) for product spot: (<a name="0051-PROD-005" href="#0051-PROD-005">0051-PROD-005</a>)
- A product of any type cannot be created without specifying at least one settlement asset (<a name="0051-PROD-001" href="#0051-PROD-001">0051-PROD-001</a>) for product spot: (<a name="0051-PROD-004" href="#0051-PROD-004">0051-PROD-004</a>) for product perpetual: (<a name="0051-PROD-007" href="#0051-PROD-007">0051-PROD-007</a>)
- The settlement asset or assets must exist at the time when the product is created (<a name="0051-PROD-002" href="#0051-PROD-002">0051-PROD-002</a>) for product spot: (<a name="0051-PROD-005" href="#0051-PROD-005">0051-PROD-005</a>) for product perpetual: (<a name="0051-PROD-008" href="#0051-PROD-008">0051-PROD-008</a>)

Product updates via governance:

- The settlement asset / settlement assets cannot be changed on a product via governance (<a name="0051-PROD-003" href="#0051-PROD-003">0051-PROD-003</a>) for product spot: (<a name="0051-PROD-006" href="#0051-PROD-006">0051-PROD-006</a>)
- The settlement asset / settlement assets cannot be changed on a product via governance (<a name="0051-PROD-003" href="#0051-PROD-003">0051-PROD-003</a>) for product spot: (<a name="0051-PROD-006" href="#0051-PROD-006">0051-PROD-006</a>) for product perpetual: (<a name="0051-PROD-009" href="#0051-PROD-009">0051-PROD-009</a>)

## See also

Expand Down
4 changes: 4 additions & 0 deletions protocol/0070-MKTD-market-decimal-places.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ Trades of course result in transfers. The amounts transferred (for the trade as
- As a user, I can propose a market with a different precision than its settlement asset
- This proposal is valid if the precision is NOT greater than the settlement asset (<a name="0070-MKTD-001" href="#0070-MKTD-001">0070-MKTD-001</a>) for product spot: (<a name="0070-MKTD-016" href="#0070-MKTD-016">0070-MKTD-016</a>)
- This proposal is NOT valid if the precision is greater than the settlement asset (<a name="0070-MKTD-002" href="#0070-MKTD-002">0070-MKTD-002</a>) for product spot: (<a name="0070-MKTD-009" href="#0070-MKTD-009">0070-MKTD-009</a>)
- As a user, I can propose a perpetual market with a different periodic settlement precision than its settlement asset
- This proposal is valid if the precision is NOT greater than the settlement asset (<a name="0070-MKTD-018" href="#0070-MKTD-018">0070-MKTD-018</a>)
- This proposal is NOT valid if the precision is greater than the settlement asset (<a name="0070-MKTD-019" href="#0070-MKTD-019">0070-MKTD-019</a>)
- As a user all orders placed (either directly or through LP) are shown in events with prices in market precision (<a name="0070-MKTD-003" href="#0070-MKTD-003">0070-MKTD-003</a>) for product spot: (<a name="0070-MKTD-010" href="#0070-MKTD-010">0070-MKTD-010</a>)
- As a user all transfers (margin top-up, release, MTM settlement) are calculated and communicated (via events) in asset precision (<a name="0070-MKTD-004" href="#0070-MKTD-004">0070-MKTD-004</a>) for product spot: (<a name="0070-MKTD-011" href="#0070-MKTD-011">0070-MKTD-011</a>)
- As a user I should see the market data prices using market precision. (<a name="0070-MKTD-005" href="#0070-MKTD-005">0070-MKTD-005</a>) for product spot: (<a name="0070-MKTD-012" href="#0070-MKTD-012">0070-MKTD-012</a>)
- Price bounds are calculated in asset precision, but enforced rounded to the closest value in market precision in range (<a name="0070-MKTD-006" href="#0070-MKTD-006">0070-MKTD-006</a>) for product spot: (<a name="0070-MKTD-013" href="#0070-MKTD-013">0070-MKTD-013</a>)
- As a user, offsets specified in pegged orders and LP shapes represent the smallest value according to the market precision (<a name="0070-MKTD-007" href="#0070-MKTD-007">0070-MKTD-007</a>) for product spot: (<a name="0070-MKTD-014" href="#0070-MKTD-014">0070-MKTD-014</a>)
- Trades prices, like orders, are shown in market precision. The transfers and margin requirements are in asset precision. ( <a name="0070-MKTD-008" href="#0070-MKTD-008">0070-MKTD-008</a>) for product spot: ( <a name="0070-MKTD-015" href="#0070-MKTD-015">0070-MKTD-015</a>)
- Settlement data received during trading on a perpetuals market is correctly handled according to the specified precision (<a name="0070-MKTD-017" href="#0070-MKTD-017">0070-MKTD-017</a>)
34 changes: 32 additions & 2 deletions protocol/0073-LIMN-limited_network_life.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,25 @@ for product spot: (<a name="0073-LIMN-101" href="#0073-LIMN-101">0073-LIMN-101</
1. The LP party has general account balance in USD of `9000` and bond account balance `1000` on the market `id_xxx`.
1. The other party has no open orders anywhere and general account balance in USD of `other_gen_bal + other_margin_bal`.

#### Test case 3.1: Spot market is proposed, accepted, restored (<a name="0073-LIMN-102" href="#0073-LIMN-102">0073-LIMN-102</a>)
#### Test case 3.1.1: Spot market is proposed, accepted, restored (<a name="0073-LIMN-102" href="#0073-LIMN-102">0073-LIMN-102</a>)

1. There is an asset USD and no asset proposals.
1. There are no markets and no market proposals.
1. There is a party a party called `LP party` with general balance of 10 000 USD.
1. A market is proposed by a party called `LP party` and has enactment date 1 year in the future. The market has id `id_xxx`.
1. `LP party` commits a stake of 1000 USD to `id_xxx`.
1. Other parties vote on the market and the proposal is accepted (passes rules for vote majority and participation). The market has id `id_xxx`.
1. The market is in `pending` state, see [market lifecycle](../protocol/0043-MKTL-market_lifecycle.md).
1. Another party places a limit sell order on the market and has `other_gen_bal`, holding balance `other_hold_bal`.
1. Enough time passes so a checkpoint is created and no party submitted any withdrawal transactions throughout.
1. The network is shut down.
1. The network is restarted with the checkpoint hash from the above checkpoint in genesis. The checkpoint restore transaction is submitted and processed.
1. There is an asset USD.
1. There is a market with `id_xxx` with all the same parameters as the accepted proposal had.
1. The LP party has general account balance in USD of `9000` and bond account balance `1000` on the market `id_xxx`.
1. The other party has no open orders anywhere and general account balance in USD of `other_gen_bal + other_hold_bal`.

#### Test case 3.1.2: Perpetual market is proposed, accepted, restored (<a name="0073-LIMN-105" href="#0073-LIMN-105">0073-LIMN-105</a>)

1. There is an asset USD and no asset proposals.
1. There are no markets and no market proposals.
Expand All @@ -181,6 +199,7 @@ for product spot: (<a name="0073-LIMN-101" href="#0073-LIMN-101">0073-LIMN-101</
#### Test case 3.2: Market is proposed, voting hasn't closed, not restored (<a name="0073-LIMN-010" href="#0073-LIMN-010">0073-LIMN-010</a>)

for product spot: (<a name="0073-LIMN-103" href="#0073-LIMN-103">0073-LIMN-103</a>)
for product perpetuals: (<a name="0073-LIMN-106" href="#0073-LIMN-106">0073-LIMN-106</a>)

1. There is an asset USD and no asset proposals.
1. There are no markets and no market proposals.
Expand All @@ -198,6 +217,8 @@ for product spot: (<a name="0073-LIMN-103" href="#0073-LIMN-103">0073-LIMN-103</

for product spot:(<a name="0073-LIMN-104" href="#0073-LIMN-104">0073-LIMN-104</a>)

for product perpetuals:(<a name="0073-LIMN-107" href="#0073-LIMN-107">0073-LIMN-107</a>)

1. There is an asset USD and no asset proposals.
1. There are no markets and no market proposals.
1. There is a party a party called `LP party` with general balance of `10 000` USD.
Expand All @@ -215,6 +236,8 @@ for product spot:(<a name="0073-LIMN-104" href="#0073-LIMN-104">0073-LIMN-104</a

for product spot: (<a name="0073-LIMN-077" href="#0073-LIMN-077">0073-LIMN-077</a>)

for product perpetuals:(<a name="0073-LIMN-108" href="#0073-LIMN-108">0073-LIMN-108</a>)

1. There is an asset USD and no asset proposals.
1. There are no markets and no market proposals.
1. There is a party a party called `LP party` with general balance of 10 000 USD.
Expand All @@ -230,6 +253,10 @@ for product spot: (<a name="0073-LIMN-077" href="#0073-LIMN-077">0073-LIMN-077</

for product spot: (<a name="0073-LIMN-078" href="#0073-LIMN-078">0073-LIMN-078</a>)


for product perpetuals:(<a name="0073-LIMN-109" href="#0073-LIMN-109">0073-LIMN-109</a>)


1. There is an asset USD and no asset proposals.
1. There are no markets and no market proposals.
1. There is a party a party called `LP party` with general balance of 10 000 USD.
Expand All @@ -245,6 +272,9 @@ for product spot: (<a name="0073-LIMN-078" href="#0073-LIMN-078">0073-LIMN-078</

for product spot: (<a name="0073-LIMN-079" href="#0073-LIMN-079">0073-LIMN-079</a>)

for product perpetuals:(<a name="0073-LIMN-110" href="#0073-LIMN-110">0073-LIMN-110</a>)


1. A party has general account balance of 100 USD.
1. The party submits a withdrawal transaction for 100 USD. A checkpoint is immediately created.
1. The network is shut down.
Expand All @@ -255,7 +285,7 @@ for product spot: (<a name="0073-LIMN-079" href="#0073-LIMN-079">0073-LIMN-079</
1. There is no market and there are no market proposals.
1. The party has general account balance in USD of `0` and The party has "signed for withdrawal" `100`.

### Test case 4a: Party's Margin Account balance is put in to a General Account balance for that asset after a reset (<a name="0073-LIMN-016" href="#0073-LIMN-016">0073-LIMN-016</a>)
### Test case 4a: Party's Margin Account balance is put in to a General Account balance for that asset after a reset (<a name="0073-LIMN-016" href="#0073-LIMN-016">0073-LIMN-016</a>) (for perpetuals: <a name="0073-LIMN-111" href="#0073-LIMN-111">0073-LIMN-111</a>)

1. A party has USD general account balance of 100 USD.
2. That party has USD margin account balance of 100 USD.
Expand Down
16 changes: 15 additions & 1 deletion protocol/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,21 @@
"0053-PERP-009",
"0053-PERP-015",
"0053-PERP-016",
"0053-PERP-017"
"0053-PERP-017",
"0043-MKTL-009",
"0051-PROD-007",
"0051-PROD-008",
"0051-PROD-009",
"0070-MKTD-017",
"0070-MKTD-018",
"0070-MKTD-019",
"0073-LIMN-105",
"0073-LIMN-106",
"0073-LIMN-107",
"0073-LIMN-108",
"0073-LIMN-109",
"0073-LIMN-110",
"0073-LIMN-111"
]
},
"Spot": {
Expand Down