When calculating funding, fillPrice should not be used as it is unfair to short traders who pay more fees for helping to balance the skew.
When calculating orderFee, fillPrice is used:
fillPrice includes a premium/discount according to how the trader affected the current market skew. As a result, shorts unfairly pay more fees when they balance the market and less when they imbalance the market.
Consider this scenario:
index price = 1000
short trade (positive price impact), fill price = 1010 => more fees are paid
short trade (negative price impact), fill price = 990 => less fees are paid
Short traders are not incentivized to balance long skew, but incentivized to worsen short skew. This leads to persistent imbalanced skew which is detrimental to all traders as fill price cannot converge with true oracle price.
https://github.com/Cyfrin/2024-07-zaros/blob/main/src/perpetuals/branches/SettlementBranch.sol#L399
Manual Review
Use an oracle price instead of fillPrice to calculate orderFee.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.