Synthetixio / synthetix-v3

MIT License
117 stars 58 forks source link

M-03: change new req margin to use current price instead of fill #2310

Closed fredsnax closed 2 weeks ago

fredsnax commented 1 month ago

… price to match liquidations

fredsnax commented 1 month ago

In getRequiredMarginWithNewPosition, newRequiredMargin is calculated with fillPrice. This is inaccurate as fillPrice includes a premium/discount, and therefore should only be used for PnL calculations.

Otherwise, a new position might be within the required margin (based on fillPrice) but immediately after settling it could be eligible for liquidation (which calculates margin based on oracle price).

This is also inconsistent with how oldRequiredMargin is calculated in the next step, which uses currentPrice.

Recommendation

Use currentPrice to calculate newRequiredMargin.