103: EMC Perps: propagate Phoenix TWAP warnings through the tree to Perpetual Contracts

This commit is contained in:
2026-10-26 06:38:53 +01:00
parent e71a8daa8d
commit cfb49ed896
22 changed files with 797 additions and 7696 deletions
+27 -6
View File
@@ -7,7 +7,7 @@ Let the owner inspect Evelyn perpetual positions grouped by wallet and venue in
## Requirements
### Requirement: Perps overview displays a collapsible position hierarchy
The Perps tab SHALL display Position, Risk, Direction, Margin, Collateral, Leverage, Exposure, Value, uPnL and TWAP beneath the visible Perpetual Contracts root. Isolated hierarchy SHALL be wallet → venue → position; each Phoenix Cross account SHALL add a Cross group above its positions. Groups SHALL show applicable totals and risk summaries, leave direction/aggregate ratios and TWAP blank, and be expanded by default.
The Perps tab SHALL display Position, Risk, Direction, Margin, Collateral, Leverage, Exposure, Value, uPnL and TWAP beneath the visible Perpetual Contracts root. Isolated hierarchy SHALL be wallet → venue → position; each Phoenix Cross account SHALL add a Cross group above its positions. Groups SHALL show applicable totals and risk summaries, leave direction/aggregate ratios blank, show TWAP warnings when applicable, and be expanded by default.
#### Scenario: Open either environment's Perps tab
- **WHEN** the owner opens Perps in Production or Test
@@ -35,12 +35,12 @@ EMC SHALL request the current Perps snapshot from each environment's own service
- **AND** a failure reading one service does not prevent attempting the other service
### Requirement: Polling preserves Perps view state
The Perps table SHALL retain matching wallet, venue and position identities across snapshots. Repeated unchanged snapshots SHALL leave retained rows, expansion, selection and formatting untouched except when risk freshness changes, without flicker or table rebuild. New groups SHALL be expanded by default, and added or removed positions SHALL be reconciled by identity without resetting retained groups.
The Perps table SHALL retain matching wallet, venue and position identities across snapshots. Repeated unchanged snapshots SHALL leave retained rows, expansion, selection and formatting untouched except when risk or TWAP-warning freshness changes, without flicker or table rebuild. New groups SHALL be expanded by default, and added or removed positions SHALL be reconciled by identity without resetting retained groups.
#### Scenario: Poll unchanged positions
- **WHEN** a user collapses a group or selects a position and repeated snapshots are unchanged
- **THEN** the same rows remain with the same expansion and selection
- **AND** only a changed risk freshness indication requires a row-value update
- **AND** only a changed risk or TWAP-warning freshness indication requires a row-value update
### Requirement: Jupiter positions communicate direction and USD size
Positions SHALL show readable Long/Short direction and Isolated/Cross margin text. USD amounts SHALL use grouping and two decimals; leverage SHALL use a multiplication sign. Signed uPnL SHALL be green for positive, red for negative and neutral for rounded zero without negative zero. Existing faint direction backgrounds SHALL remain; groups SHALL have distinct weight and no direction color. Numeric columns SHALL be right-aligned with useful widths and tooltips.
@@ -70,10 +70,10 @@ Tooltips SHALL explain isolated collateral, exposure-based leverage, collateral-
- **AND** no position-only metric is labeled account utilization
### Requirement: Venue visibility follows available child rows
EMC SHALL hide venue rows with neither positions nor Cross accounts and show them when children reappear. Funded empty Cross accounts SHALL keep their venue visible. Hidden venues SHALL remain in snapshots and totals, with read status available in wallet tooltips. Unknown scopes SHALL NOT become zero totals; failed reads SHALL preserve last-success totals. Wallet rows and the root SHALL remain visible.
EMC SHALL hide venue rows with neither positions, Cross accounts nor TWAP warnings and show them when children reappear. Funded empty Cross accounts and accounts with eligible TWAP warnings SHALL keep their venue visible. Unmatched isolated warnings SHALL remain on the venue with true subaccount identity, never on an invented Cross parent. Hidden venues SHALL remain in snapshots and totals, with read status available in wallet tooltips. Unknown scopes SHALL NOT become zero totals; failed reads SHALL preserve last-success totals. Wallet rows and the root SHALL remain visible.
#### Scenario: Empty venue
- **WHEN** Jupiter or Phoenix has no positions and no Cross accounts
- **WHEN** Jupiter or Phoenix has no positions, Cross accounts or TWAP warnings
- **THEN** its heading is absent from that wallet's displayed children
- **AND** a successful empty scope still contributes zero to totals
@@ -92,7 +92,7 @@ EMC SHALL hide venue rows with neither positions nor Cross accounts and show the
- **AND** required totals remain unavailable rather than reporting zero
### Requirement: TWAP cells show execution progress and snapshot duration
Matching filled Phoenix TWAPs SHALL show a progressbar using executed/total child counts and an overlaid estimated duration to the next child in unbounded hours, minutes and seconds. Other cells SHALL be empty. Updates SHALL follow existing snapshots without a live timer. Failed retained observations SHALL be labeled retained; due or unknown schedules SHALL not show negative or wrapped times or imply execution.
Matching filled Phoenix TWAPs SHALL show a progressbar using executed/total child counts and an overlaid estimated duration to the next child in unbounded hours, minutes and seconds. Cells with no eligible progress or warning SHALL be empty. Matched timing warnings SHALL coexist with their progressbar. Updates SHALL follow existing snapshots without a live timer. Failed retained observations SHALL be labeled retained; due or unknown schedules SHALL not show negative or wrapped times or imply execution.
#### Scenario: Long interval
- **WHEN** the snapshot's estimated wait is 28 hours 32 minutes 10 seconds, or 128 hours 32 minutes 10 seconds
@@ -126,3 +126,24 @@ EMC SHALL mark risk stale after five minutes from its original observation, on r
#### Scenario: Retained critical risk
- **WHEN** a previously critical observation fails to refresh
- **THEN** its critical state and original time remain visible with stale/retained indication
### Requirement: TWAP warnings propagate through every ancestor
EMC SHALL show an amber warning triangle and concise text at the owning position or Cross group and on every actual ancestor through Perpetual Contracts. Summaries SHALL count each distinct order once per scope independently of expansion state. Unfilled and completed orders SHALL remain invisible. Risk and capital totals SHALL remain independent.
#### Scenario: Collapsed Cross branch
- **WHEN** a filled outstanding Cross order has missing market metadata and Cross or Phoenix is collapsed
- **THEN** Cross, Phoenix, wallet and Perpetual Contracts still carry the warning
- **AND** each summary counts that order once
#### Scenario: Position and multiple wallets
- **WHEN** a position warning and an unmatched Cross warning affect different wallets
- **THEN** each follows only its actual ancestors and the root counts two orders
- **AND** clearing one warning leaves the other and its ancestor summaries intact
### Requirement: Warning details preserve reason and freshness
Warning tooltips SHALL identify wallet/account/position, reason, TWAP address, asset/subaccount IDs, raw progress/fills and original observation time. Unknown metadata SHALL remain unknown without unsupported cancellation/delisting/stoppage claims. Failure retention, future timestamps and the existing five-minute observation-age cutoff SHALL qualify all affected summaries.
#### Scenario: Retained or aged warning
- **WHEN** a warned venue or consumer read fails, or its original observation becomes five minutes old
- **THEN** source and inherited warnings remain visible with retained/stale qualification and original times
- **AND** existing UI polling updates age without additional venue reads or resetting selection and expansion
+14 -3
View File
@@ -85,17 +85,28 @@ Each venue SHALL carry its last-success time and whether the latest attempt fail
- **THEN** its previous observations remain available with their original success time and failure indication
### Requirement: TWAP observations belong to existing filled positions
The service SHALL publish immutable TWAP observations only on matching existing Phoenix positions whose order has a positive actual fill and remaining executions. It SHALL preserve counters, quantities, nullable price and observation/estimated times without UI formatting. No new position SHALL be synthesized. TWAP errors SHALL retain the complete prior venue observation with failure status. Polling frequency SHALL remain unchanged.
The service SHALL publish immutable TWAP observations on matching existing Phoenix positions whose order has a positive actual fill and remaining executions, and account-owned warnings for eligible unresolved orders. It SHALL preserve counters, quantities, nullable price and observation/estimated times without UI formatting. No new position SHALL be synthesized. TWAP errors SHALL retain the complete prior venue observation with failure status. Polling frequency SHALL remain unchanged.
#### Scenario: Unfilled order or no position
- **WHEN** an active TWAP has no actual fills or has no matching open position
- **THEN** it is absent from every overview row and cannot create a visible venue
- **WHEN** an active TWAP has no actual fills or no matching open position
- **THEN** a zero-fill order is absent from every overview row and cannot create a visible venue
- **AND** an eligible filled outstanding order without a position is preserved as a warning on its actual account scope
#### Scenario: TWAP read fails
- **WHEN** the TWAP read fails after a successful venue observation
- **THEN** prior positions, TWAP observations and original timestamps remain with failed venue status
- **AND** other venues and wallets continue refreshing
#### Scenario: Filled order without position
- **WHEN** a filled outstanding order cannot match an open position
- **THEN** its warning retains the real account identity and Cross accounts remain present even without capital or positions
- **AND** warning-only data does not synthesize positions or valuations
#### Scenario: Warning recovery and retention
- **WHEN** a successful observation resolves or removes a warned order
- **THEN** its warning is cleared while unrelated warnings remain
- **AND** failed reads instead retain warnings and their original times
### Requirement: Risk observations preserve scope and exact meaning
Snapshots SHALL preserve isolated risk prices and Cross account tiers/thresholds with original observation times. Signed price distance SHALL use the current venue reference as denominator and preserve boundary crossing. Cross MM utilization SHALL use effective collateral, with nonpositive denominators unavailable. Group risk SHALL count each isolated position and shared account once and retain worst known severity plus unknown/stale counts without averaging.
+21 -4
View File
@@ -33,8 +33,8 @@ HTTP, authentication, malformed schema, identity mismatch and numeric conversion
- **THEN** the read fails instead of returning an empty or partial portfolio
#### Scenario: Empty account
- **WHEN** a valid trader snapshot has no subaccounts or no nonzero positions
- **THEN** an empty result is returned without market-price or TWAP requests
- **WHEN** a valid trader snapshot has no subaccounts
- **THEN** an empty result is returned without market-price or TWAP requests; existing empty subaccounts still receive TWAP discovery
#### Scenario: Public API rate limit
- **WHEN** the shared adapter issues requests for PROD and TEST
@@ -62,7 +62,7 @@ Equity SHALL include collateral, undiscounted price PnL and signed unsettled fun
- **AND** effective Cross leverage uses 103 USD as its denominator
### Requirement: Read precise TWAP snapshots for held markets
The reader SHALL read official TWAP snapshots through its existing paced transport and associate orders by authority, PDA, subaccount and market identity. Only orders with actual fills and remaining children on an existing position SHALL be exposed. Quantities SHALL use exact lot conversion and explicit/legacy dust semantics. Unavailable size inputs SHALL remain unknown. Existing mark prices SHALL be reused without Ticker reads.
The reader SHALL read official TWAP snapshots through its existing paced transport and associate orders by authority, PDA, subaccount and market identity. Only orders with actual fills and remaining children SHALL be exposed. Matched orders SHALL retain position progress; valid unresolved orders SHALL retain account-owned warnings with identity, raw counters/fills and original observation time. Existing accounts without positions SHALL receive TWAP discovery. Quantities SHALL use exact lot conversion and explicit/legacy dust semantics. Unavailable size inputs SHALL remain unknown. Existing mark prices SHALL be reused without Ticker reads.
#### Scenario: Explicit and legacy dust
- **WHEN** total children are 5, regular size 10 lots and explicit dust count/size are 2/3
@@ -71,7 +71,24 @@ The reader SHALL read official TWAP snapshots through its existing paced transpo
#### Scenario: Identity mismatch or unfilled order
- **WHEN** authority/PDA/subaccount/asset identities disagree or an order has no fills
- **THEN** disagreement fails the read, while a valid unfilled order is absent from returned positions' TWAP data
- **THEN** disagreement fails the read, while a valid unfilled order is absent from all TWAP data and warnings
#### Scenario: Missing market or missing position
- **WHEN** a filled outstanding order has missing market metadata or no matching open position
- **THEN** a warning preserves its identity and raw progress without inventing a symbol, conversion, price or execution status
- **AND** healthy positions and account risk remain available
#### Scenario: Existing empty account
- **WHEN** an account has no held positions but has a filled outstanding TWAP
- **THEN** TWAP discovery returns its warning without fetching market prices or creating positions
#### Scenario: Completed order
- **WHEN** an order has no remaining children
- **THEN** it is absent from active TWAP data and warnings
#### Scenario: Matched order with unavailable timing
- **WHEN** an otherwise valid matched filled order has no usable future next-execution estimate
- **THEN** its progress remains available with a timing warning that does not assert execution has stopped
### Requirement: TWAP time estimates disclose their slot assumption
The reader SHALL estimate future execution times from snapshot slot, due slot and cooldown using a documented nominal slot duration and response observation time. Completion SHALL derive from remaining executions, never expiry. Already-due schedules, invalidated completion schedules and unrepresentable estimates SHALL remain unavailable instead of predicting fills.