- Unrealized PnL
- Maintenance margin checks
- Funding rate TWAP inputs
Formula
If there has been no trade yet,last_trade_price defaults to the oracle price.
Why clamped?
Without the clamp, a thinly-traded market could be manipulated, one fill at +50% would make every long position look wildly profitable, passing margin checks they shouldn’t. The 10% clamp window:- Tight enough that adversarial trades can’t push users into insolvency via mark alone.
- Wide enough that legitimate price discovery during a volatile hour still moves mark organically (versus just pinning it to oracle).
What updates mark
- Every fill updates
orderbook.last_trade_priceandlast_trade_ts. update_funding_ratereads the current mark into the mark TWAP.- Admin param changes never rewrite mark directly.
TWAPs
Two 1-hour exponential moving averages are maintained on theMarket account:
mark_twap, 1-hour EMA of mark priceoracle_twap, 1-hour EMA of oracle price
Reading mark price off-chain
math::get_mark_price(market, oracle) server-side
via a Codama-generated helper.
