-
Notifications
You must be signed in to change notification settings - Fork 47
chore: reorder rp update on deficit #1078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 21 commits
32fc97f
b2e00ab
895d7b2
0c1bac0
415bf3b
29d6c4f
90ecea1
511ac7d
a46478b
72a4c14
b1425a0
3f6f396
1f0a705
5bb8ded
9c7abd7
9dac5fc
eec574e
99213f7
362f535
2fb5e97
bd60b7b
dc33d4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,14 +258,15 @@ library LiquidationLogic { | |
| /// @param positionStatus The mapping of position status per user. | ||
| /// @param reserveCount The number of reserves. | ||
| /// @param user The address of the user. | ||
| function reportDeficit( | ||
| function notifyReportDeficit( | ||
| mapping(uint256 reserveId => ISpoke.Reserve) storage reserves, | ||
| mapping(address user => mapping(uint256 reserveId => ISpoke.UserPosition)) storage userPositions, | ||
| mapping(address user => ISpoke.PositionStatus) storage positionStatus, | ||
| uint256 reserveCount, | ||
| address user | ||
| ) external { | ||
| ISpoke.PositionStatus storage userPositionStatus = positionStatus[user]; | ||
| userPositionStatus.riskPremium = 0; | ||
|
|
||
| uint256 reserveId = reserveCount; | ||
| while ( | ||
|
|
@@ -298,6 +299,8 @@ library LiquidationLogic { | |
|
|
||
| emit ISpoke.ReportDeficit(reserveId, user, debtComponents.drawnShares, premiumDelta); | ||
| } | ||
|
|
||
| emit ISpoke.UpdateUserRiskPremium(user, 0); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is being emitted even if the risk premium was already 0. We d need to do smt like to avoid emitting false events... I d keep the code as is OR create an internal helper for updating user risk premium that i) returns early if not needed, ii) update storage and iii) emit event.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its just a redundant event, idt it's 'false'. to me its fine as is internal helper will make the logic of _notifyRiskPremium more expensive
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you fine with the redudant event in this case? it d make the logic of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it adds additional comparator which is more expensive in the general case, the redundant event is only redundant in one case when prev rp is 0; im fine here because next rp bc of report deficit is always 0 the logic is simpler w/o suggestion but i'm happy to apply
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We agreed to accept the redundancy, as it makes deficit scenarios more explicit when the system fully clears a user position, without impacting gas efficiency in the average case. |
||
| } | ||
|
|
||
| /// @notice Calculates the liquidation bonus at a given health factor. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the question, when reading this fn you can assume either
i.
_reportDeficitonly clears user debt and notify so we must_notifyRiskPremiumUpdateat the end no matter what (dev)ii.
_reportDeficitalso clears risk premium so we don't need to notify later. (PR)imo:
i. option follow single responsability principle, and makes liq fn more readable
ii. option is more self-contained and favors reusability. It's only used once and worsen liq fn readabiltiy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single responsibility is readable but more error prone imo, since the true action is contained in two methods
i think renaming to notifyReportDefict or reportAndNotifyDeficit is a great suggestion to improve the lost readability