Core Technical Mechanisms

1. Real-Time Price & Probability Engine

  • Data Source: The shares amount for each outcome in a market's liquidity pool.

  • Calculation: The price of an outcome token is derived from the constant product AMM model used by Polkamarkets.

    • Price_outcome_i = (shares_outcome_i) / (total_shares_in_market)

  • Implied Probability: The price is directly interpreted as the market's implied probability of that outcome occurring.

    • Implied_Probability_outcome_i = Price_outcome_i * 100

  • Update Trigger: This calculation is recomputed and stored in the database on every PositionMinted, PositionRedeemed, and PositionTraded event.

2. User Profit & Loss (PnL) Aggregator

Polysight implements a comprehensive PnL tracking system.

  • Realized PnL: Calculated upon redeeming a winning position or selling a position.

    • Realized PnL = (Redemption/Sale Value in POLK) - (Total Cost Basis in POLK)

  • Unrealized PnL: Calculated for active, unresolved positions based on the current market price.

    • Unrealized PnL = (Current Position Value based on Price) - (Cost Basis)

  • Cost Basis Tracking: Implemented via a FIFO ledger in the user_positions table. Each "buy" creates a new ledger entry. When a position is partially or fully closed, the oldest ledger entries are reduced first, and the PnL is realized accordingly.

3. Leaderboard Ranking Algorithm

Leaderboards are not simple sorts; they are powered by materialized views or incrementally updated aggregates.

  • Key Metrics:

    • Total PnL: Sum of all realized PnL + unrealized PnL.

    • Accuracy Score: (Number of Correct Predictions) / (Total Number of Resolved Predictions). Only markets where the user held a position at resolution are counted.

    • Volume Weighted Accuracy: Accuracy score weighted by the POLK volume of each prediction, giving more significance to high-stakes correct predictions.

  • Implementation: A dedicated aggregation job runs periodically (e.g., every 10 minutes) or is triggered by market resolution events to update the user_analytics table, which the leaderboard query reads from.

Last updated