You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on #537, I noticed that negative interest isn't being applied correctly to shorts and longs in _applyCheckpoint. The current implementation contains this logic:
// Close out the short positions with a maturity time equal to the latest checkpoint.
// This ensures that shorts don't continue to collect free variable interest and
// ensures that LP's can withdraw the proceeds of their side of the trade.
uint256 maturedShortsAmount = _totalSupply[
AssetId.encodeAssetId(AssetId.AssetIdPrefix.Short, _checkpointTime)
];
if (maturedShortsAmount > 0) {
uint256 shareProceeds = maturedShortsAmount.divDown(_sharePrice);
uint256 flatFee = shareProceeds.mulDown(_flatFee);
uint256 govFee = flatFee.mulDown(_governanceFee);
// Add accrued governance fees to the totalGovernanceFeesAccrued in terms of shares
_governanceFeesAccrued += govFee;
// Increase shareProceeds by the flatFeeCharged, and less the govFee from the amount as it doesn't count
// towards reserves. shareProceeds will only be used to update reserves, so its fine to take fees here.
shareProceeds += flatFee - govFee;
// Closing out shorts first helps with netting by ensuring the LP funds
// that were netted with longs are back in the shareReserves before we
// close out the longs.
_applyCloseShort(
maturedShortsAmount,
0,
shareProceeds,
0,
_checkpointTime,
_sharePrice
);
}
// Close out the long positions with a maturity time equal to the latest checkpoint.
uint256 maturedLongsAmount = _totalSupply[
AssetId.encodeAssetId(AssetId.AssetIdPrefix.Long, _checkpointTime)
];
if (maturedLongsAmount > 0) {
uint256 shareProceeds = maturedLongsAmount.divDown(_sharePrice);
uint256 flatFee = shareProceeds.mulDown(_flatFee);
uint256 govFee = flatFee.mulDown(_governanceFee);
// Add accrued governance fees to the totalGovernanceFeesAccrued in terms of shares
_governanceFeesAccrued += govFee;
// Reduce shareProceeds by the flatFeeCharged, and less the govFee from the amount as it doesn't count
// towards reserves. shareProceeds will only be used to update reserves, so its fine to take fees here.
shareProceeds -= flatFee - govFee;
_applyCloseLong(
maturedLongsAmount,
0,
shareProceeds,
0,
_checkpointTime,
_sharePrice
);
}
We normally adjust the share proceeds and reserves deltas to account for negative interest in the calculation functions. Since the logic is simpler in _applyCheckpoint, we just included the logic inline in _applyCheckpoint, which results in this issue.
Solution
We should apply the negative interest logic. Aside from this, we should refactor the code so that we have calculation methods.
The text was updated successfully, but these errors were encountered:
Problem
While working on #537, I noticed that negative interest isn't being applied correctly to shorts and longs in
_applyCheckpoint
. The current implementation contains this logic:We normally adjust the share proceeds and reserves deltas to account for negative interest in the calculation functions. Since the logic is simpler in
_applyCheckpoint
, we just included the logic inline in_applyCheckpoint
, which results in this issue.Solution
We should apply the negative interest logic. Aside from this, we should refactor the code so that we have calculation methods.
The text was updated successfully, but these errors were encountered: