Category: Coding Mistakes
Partial closes emit incorrect value in TradeReferred event
Low Impact
Low Severity
Low Likelihood
Description
When a trade is partially closed, _unregisterTrade calls storageT.applyReferralClose to apply the referral close:
function _unregisterTrade(
ITradingStorage.Trade memory _trade,
int _percentProfit,
uint _collateral,
uint _feeAmountToken, // executor reward
uint _lpFeeToken,
uint _tier
) private returns (uint usdcSentToTrader) {
//...
(uint feeAfterRebate, uint referrerRebate) =
storageT.applyReferralClose(
_trade.trader,
_lpFeeToken,
_trade.initialPosToken.mul(_trade.leverage)
);However, the third parameter to applyReferralClose should be the size of the leveraged position that was closed, instead of the total leveraged position.
In applyReferralClose, the third parameter is only used in the emitted TradeReferred event.
Impact
The emitted TradeReferred event for a partial close will have an incorrect closed leveraged position size.
Recommendations
Make this _collateral.mul(_trade.leverage).
Remediation
This issue has been acknowledged by Avantis Labs, Inc., and a fix was implemented in commit f4ef1c84↗.