-
Notifications
You must be signed in to change notification settings - Fork 0
🩹 market: mirror fixed repay rounding in position preview #10
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@exactly/lib": patch | ||
| --- | ||
|
|
||
| 🩹 market: mirror fixed repay rounding in position preview |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,11 @@ export default function fixedRepayPosition( | |
| const r = mulDiv(netUnassignedEarnings, k, backupSupplied); | ||
| if (r >= WAD) return min(assets + netUnassignedEarnings, totalPosition); | ||
| const x = divWad(assets, WAD - r); | ||
| if (mulWad(k, x) <= backupSupplied && x <= totalPosition) return x; | ||
| const scaledPrincipal = mulDiv(x, principal, totalPosition); | ||
| const gross = mulDiv(unassignedEarnings, min(scaledPrincipal, backupSupplied), backupSupplied); | ||
| const pos = min(assets + gross - mulWad(gross, backupFeeRate), totalPosition); | ||
| const earned = mulDiv(unassignedEarnings, min(mulDiv(pos, principal, totalPosition), backupSupplied), backupSupplied); | ||
| const repay = pos - earned + mulWad(earned, backupFeeRate); | ||
| if (scaledPrincipal <= backupSupplied && x <= totalPosition) return pos - (repay > assets ? repay - assets : 0n); | ||
|
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. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Consider documenting the return adjustment logic. The expression 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.
After this patch's one-shot subtraction, the returned position can still cost more than the caller's asset limit because lowering Useful? React with 👍 / 👎. |
||
| return min(assets + netUnassignedEarnings, totalPosition); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.